Loading

Quipoin Menu

Learn • Practice • Grow

java-script / let & const
interview

Q1. What are let and const
let and const are keywords used to declare variables in JavaScript. They were introduced in ES6 (ECMAScript 2015) as improved alternatives to var.
They help developers write safer and more predictable code by providing block-level scope and better control over variable reassignment.


Q2. What is block scope?
Block scope means a variable is accessible only inside the block where it is declared. A block is defined using curly braces { }.

Example
{
    let name = "John";
    console.log(name);
}

The variable name can only be accessed inside the block. Accessing it outside the block will cause an error.


Q3. Can a let variable be reassigned?
Yes, a let variable can be reassigned, but it cannot be redeclared in the same scope.

Example
let age = 25;
age = 30;
console.log(age);



Q4. Does const make objects immutable?
No, const prevents reassignment of the variable reference, but it does not make the object immutable.

Example
const person = {
    name: "John"
};

person.name = "Mike";
console.log(person.name);

The object properties can still be changed, but the object itself cannot be reassigned.


Q5. What happens if let or const is accessed before declaration?
Accessing let or const variables before declaration results in a ReferenceError.

This happens because they are in the Temporal Dead Zone (TDZ), which is the time between entering the scope and declaring the variable.