Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

204
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda