Hackforge Academy

Category: React • Beginner

Published on 18 Feb 2026

Explanation

#white-const is a keyword introduced in ES6 used #white-to declare variables with block scope. It creates #white-a constant reference that cannot be reassigned.

Code Example

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

Explanation

#white-Variables declared with const are block scoped, meaning #white-they are only accessible within the block where #white-they are defined.

Code Example

{
  const x = 10;
  console.log(x);
}
// console.log(x); // Error

Explanation

#white-A const variable cannot be reassigned after its #white-initial declaration.

Code Example

const age = 25;
// age = 30; // Error: Assignment to constant variable

Explanation

#white-const variables must be initialized at the time #white-of declaration.

Code Example

// const count; // Error
const count = 5;

Explanation

#white-When using const with objects or arrays, the #white-reference cannot change, but the properties or elements #white-can be modified.

Code Example

const user = { name: "Praveen" };
user.name = "Kumar";
console.log(user.name);

const numbers = [1, 2, 3];
numbers.push(4);
console.log(numbers);

Explanation

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

Code Example

const id = 1;
// const id = 2; // Error

Want structured learning with real projects?

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