when i set an item in session storage, (then refresh the page) and then set a variable as the item, for some reason it sets that variable as either NaN or null, how can i stop this? (save files)
var myVar = false;
function save() {
sessionStorage.setItem("myVar", myVar)
}
function load(){
myVar = sessionStorage.getItem("myVar")
myVar = parseInt(myVar) //is supposed to set myVar as the stored variable called "myVar"
//if i do console.log() and print the variable value, it either shows up as NaN or Null
//if i didnt do 'parseInt' then the value will be 'false', but the value is in strings???
//(when value is in strings, it wont work in an "if (myVar == false){}")
}
>Solution :
Values stored in sessionStorage are strings.
Use this to convert to boolean :
myVar = sessionStorage.getItem("myVar") === "true";