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

223
Views
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 answers
Answer question

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 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!