'SessionStorage setting variable boolean as NaN or null (Javascript) [closed]
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){}")
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
