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

180
Views
"Why" JavaScript hoists "let" and "const" variable and keep them in temporal zone? so what is the benefit for this behavior?

Why javascript do hoist on let and const variables and we can't reach them until the initialization and in this way, end temporal dead zone. Is there a particular benefit for this behavior? why js doesn't leave those without any hositing on those?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Because when you shadow a variable, it would be unclear to which variable an identifier would refer in the temporal dead zone, especially as variables declared with var are hoisted too. As such let and const are consistent with var as they are also hoisted, but they're more restrictive in situations where var has shown confusing behavior.

 let val = "a";
 {
    console.log(val);
    let val = "b";
 }
about 4 years ago · Juan Pablo Isaza Report

0

Programming languages generally have a tradition like variables should be defined at the top. Behind the scenes JS is a part of this tradition too. It hoists var to the top and sets it to undefined until it's defined. This behaviour might lead unwanted consequences because JS will attempt like it's just a normal variable and try to do something with that undefined however since there is nothing you will get an error. So they introduced let and const keywords to prevent this bad behaviour and said these are also hoists and we set them to uninitiliazedand you can't use them until they're assigned to something because that has no meaning, why would you want to use a variable before it assigned to something?

about 4 years ago · Juan Pablo Isaza Report

0

wall it makes things more clear -sometimes you have to declare the same name of variable multiple times and you don't want to mix up their values

-when you use var it declares on a global scope and after function runs successfully it doesn't clear meemory it stay there in this case if you have many many variables that require too much memory is going to affect on your app performans

in your case:-

     let val = "a"; // this let have globle scope
 {
    console.log(val);
    let val = "b"; // this let have local scope that going to be clear from memory when this brakets endes 
 }

Conclusion:-

var is a global scope
let & const are BLOCK scope that going to be clear after brackets ended
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!