Understanding Scope in Javascript


Variables have function scope or block scope (let and const).

Source Code

function testScope() {
  let localVar = 'I am local';
  console.log(localVar); // Accessible here
}
console.log(localVar); // Error: localVar is not defined
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments