Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

205
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda