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

226
Visualizações
Where is this value come from? (javascript localStorage)

I included this javascript file in my php web page. I use a if statement to see if the value of tried_or_not2 is yes. Here is the code.

let tried_or_not2 = localStorage.getItem('tried_or_not2');
form_for_login.style['visibility'] = 'visible';

console.log('test1', localStorage.getItem('tried_or_not2'));

if (tried_or_not2 !== 'yes') {
    console.log('test2');
    localStorage.setItem('tried_or_not2', 'yes');
    invitation_code.value = localStorage.getItem('invitation_code');
    password.value = localStorage.getItem('password');
    console.log('test3');
    form_for_login.submit();
    console.log('test4');
}

console.log('test5');

Here is the result.

https://i.stack.imgur.com/SxfB4.png

We can see test1, yes , test5 on the console. But when I comment the line

localStorage.setItem('tried_or_not2', 'yes');

the value of tried_or_not2 becomes null. That means the value of tried_or_not2 is created at that line ,right? But, why does it print yes at first? Thank you very much!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Unless you're clearing the localStorage before reloading, the previous values will persist. Meaning that even if you don't set the value now, the value you set previously will still be available. If you want the values to be cleared after the tab is closed, use sessionStorage instead. Or just clear the value after the page loads.

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