Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

202
Views
SessionStorage setting variable boolean as NaN or null (Javascript)

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){}")
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Values stored in sessionStorage are strings.

Use this to convert to boolean :

myVar = sessionStorage.getItem("myVar") === "true";

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!