Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Question 1 of 10 · JavaScript Basics & Fundamentals
Interview question

What are the differences between var, let, and const in JavaScript? JavaScript में var, let और const में क्या अंतर है?

Answer
KeywordScopeHoistingRe-declarationRe-assignment
varFunction-scopedHoisted, initialized as undefinedYesYes
letBlock-scopedHoisted but not initialized (TDZ)NoYes
constBlock-scopedHoisted but not initialized (TDZ)NoNo
function test() {
    console.log(x); // undefined (hoisting)
    var x = 1;
    
    if (true) {
        let y = 2;  // block-scoped
        const z = 3; // block-scoped, can't be reassigned
    }
    console.log(y); // ReferenceError: y is not defined
}

Interview tip: Always use const by default, let if reassignment needed, and avoid var. Mention Temporal Dead Zone (TDZ) for let/const.

KeywordScopeHoistingRe-declarationRe-assignment
varFunction-scopedHoisted, undefinedहाँहाँ
letBlock-scopedHoisted नहीं (TDZ)नहींहाँ
constBlock-scopedHoisted नहीं (TDZ)नहींनहीं
function test() {
    console.log(x); // undefined (hoisting)
    var x = 1;
    
    if (true) {
        let y = 2;  // block-scoped
        const z = 3; // block-scoped
    }
    console.log(y); // ReferenceError
}

इंटरव्यू टिप: Default const use करें, reassignment चाहिए तो let, var से बचें। Temporal Dead Zone (TDZ) का ज़िक्र करें।

Was this answer clear?