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

81
Views
How do block scopes have access to enclosing scope

i do understand that due to lexical scoping, block scopes can access the enclosing scope variables. But what i do not understand is how it really works. ex:

function first(){
  let i=10;
  function second(){
    let j=20;
    console.log(i);
    if(j==20){
    console.log(i);
  } 
  }
  second();
}

the first console.log() get the value of i after its looks up the scope chain in the variable object. But how does the console.log() inside the block get access to variable i as it does not create an execution context and thus no scope chain.

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

0

js engine stores hoisted ( by hoisting ) variable and function declarations to the top of particular scope in which that variable or function is declared. Assignment operations aren't hoisted. So engine knows in which scope variable or function is declared.

https://medium.com/@venomnert/how-js-engine-reads-your-code-df3cd36e4192

above article describes how js engine finds variables and some other concepts which can be helpful to understand closures and execution of code.

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!