Correct use of front-end storage

I have a simple question regarding the use of storage commands. Specifically something like session.setItem(“key”, “value”). Should I remove the session item before resetting it to it’s new value? Which of the below is correct:

option 1:
session.setItem(“key”, “true”)



session.setItem(“key”, “false”)

option 2:
session.setItem(“key”, “true”)



session.removeItem(“key”);
session.setItem(“key”, “false”);

With variables, you have to declare them first i.e. let x=1 and change them i.e. x=2. Storage seems to function differently. Please help me understand the correct use of storage commands. I’ve looked at the online documentation and it’s not helping.

Out of my knowledge → you do not have to remove the key each time.
Normaly it will overwrite the old value.

But maybe something again changed in the APIs.

Why you dot not testing it on your own ?

We write data to SESSION-STORAGE:…
session.setItem('key', 'true')

We use a TIMER to get the data back out of the storage…

setTimeOut(()=>{
    let storageValue = session.getItem('key');
    console.log('Loaded-Value: ', storageValue );
},1500);

We do it again, setting another value for the -->same ← —> key <—

session.setItem('key', 'false');

setTimeOut(()=>{
    let storageValue = session.getItem('key');
    console.log('Loaded-Value: ', storageValue );
},1500);

What do you get as RESULT ???

To give the whole testing-setup a better overview, you add 2 buttons, which will simulate of setting FIRST STORAGE-VALUE and SECOND STORAGE-VALUE.

$w.onReady(()=>{
    $w(#'button1').onClick(()=>{});

    $w(#'button1').onClick(()=>{});
});

Completed TESTING-CODE…

$w.onReady(()=>{
    $w(#'button1').onClick((e)=>{console.log(e.target.id+'-clicked');
        session.setItem('key', 'true');
        setTimeOut(()=>{
            let storageValue = session.getItem('key');
            console.log('Loaded-Value: ', storageValue );
        },1500);

    $w(#'button2').onClick((e)=>{console.log(e.target.id+'-clicked');
        session.setItem('key', 'false');
        setTimeOut(()=>{
            let storageValue = session.getItem('key');
            console.log('Loaded-Value: ', storageValue );
        },1500);
    });
});

CONCLUSION… ??? → already took a look into → CONSOLE ?