I noticed this anomaly working with application-settings module on a nativescript (8.1.2) /angular project.

Having this code:

import { getString} from '@nativescript/core/application-settings';

remove("attribute_name_string")

let attribute_name_string = getString("attribute_name_string","DEFAULT VALUE")

console.log("Print My Local Atribute = " + attribute_name_string)

I was expected the result to be:

Print My Local Atribute = DEFAULT VALUE 
but it was
Print My Local Atribute = 

The same for setNumber

import { setNumber} from '@nativescript/core/application-settings';
    
    remove("attribute_name_number")

    let attribute_name_number = getNumber("attribute_name_number", 121)

    console.log("Print My Local Atribute Number = " + attribute_name_number)

I was expected the result to be:

Print My Local Atribute Number = 121 
but it was
Print My Local Atribute Number = 0

Two questions here:

  1. Why this strange behaviour (anomaly)?

  2. How can I clear my variables and get the default value afterwards ?

Please take in consideration the official documentation: A default value can be provided in case there is no existing value.

    /**
     * Gets a value (if existing) for a key as a String Object. 
A default value can be provided in case there is no existing value.
     * @param key The key to check for.
     * @param defaultValue An optional value to be returned in case there is no existing value.
     */
    export function getString(key: string, defaultValue?: string): string;

and

/**
 * Removes a value (if existing) for a key.
 * @param key The key to check for.
 */
export function remove(key: string): void;
0

There are 0 best solutions below