Hackforge Academy

Category: React • Beginner

Published on 18 Feb 2026

Explanation

#white-let is a keyword introduced in ES6 used #white-to declare variables with block scope.

Code Example

let name = "Praveen";
console.log(name);

Explanation

#white-Variables declared with let are limited to the #white-block in which they are defined (inside {} #white-braces).

Code Example

{
  let x = 10;
  console.log(x);
}
// console.log(x); // Error: x is not defined

Explanation

#white-Variables declared with let can be reassigned with #white-a new value.

Code Example

let count = 5;
count = 10;
console.log(count);

Explanation

#white-You cannot redeclare a variable with let in #white-the same scope.

Code Example

let age = 25;
// let age = 30; // Error: Identifier 'age' has already been declared

Explanation

#white-var has function scope, while let has block #white-scope. let is safer and avoids scope-related issues.

Code Example

if (true) {
  var a = 1;
  let b = 2;
}

console.log(a); // Works
// console.log(b); // Error

Explanation

#white-Variables declared with let cannot be accessed before #white-their declaration due to the Temporal Dead Zone.

Code Example

// console.log(x); // Error
let x = 10;
console.log(x);

Want structured learning with real projects?

Join our Weekend Live Workshop and become job-ready faster.