Important Concepts Along with Interview Questions and Answers

<aside> 💡 This document covers understanding var, let, and const in JavaScript. It includes the concepts of variable shadowing, illegal shadowing, hoisting, and the temporal dead zone.

</aside>

Var, Let and Const

1. Variable Shadowing

Notes:

Example:

function test() {
  let a = "Hello"; // Outer variable

  if (true) {
    let a = "Hello World"; // Inner variable shadows the outer one
    console.log(a); // Prints "Hello World"
  }

  console.log(a); // Prints "Hello"
}

test();

Explanation:

2. Illegal Shadowing

Notes: