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

340
Views
What is difference between let , const and var in case of variable shadowing /re declaration in different scope?

Please check below 2 code snippets the difference is redeclaring as const/let and var in foo function.

for var, it executes but for const and let it throughs error.

Please tell me why it behaves differently.

Below code does not through any error as a is declared as var
var a=12; //Global variable
foo(); //hoisting 
function foo() {
    console.log("a="+a);
    var a=13;
    console.log("a="+a);
    if(true) {
        const a=89;
        console.log("in block="+ a);
    }
    var a=90;    //no error
    console.log("a="+a);    
}

Below code throughs variable declaration error "a has already been declared"

var a=12; //Global variable
foo(); //hoisting 
function foo() {
    console.log("a="+a);
    var a=13;
    console.log("a="+a);
    if(true) {
        const a=89;
        console.log("in block="+ a);
    }
    let a=90;    //Or const a :: error
    console.log("a="+a);    
}
about 4 years ago · Juan Pablo Isaza
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!