All Interview Questions
About Lesson

Q3. What will be the output of this code? Also explain why

let a = 10;
console.log(“line number 2”, a);

function fn() {
    console.log(“line number 4”, a);
    let a = 20;
    a++;
    console.log(“line number 7”, a);
    if (a) {
        let a = 30;
        a++;
        console.log(“line number 11”, a);
    }
    console.log(“line number 13”, a);
}
fn();
console.log(“line number 16”, a);
ans:

Output ->
Line has runtime error: console.log(“line number 4”, a);
if we will hide it, then the result
console.log(“line number 2”, 10);
console.log(“line number 7”,21);
console.log(“line number 11”, 31);
console.log(“line number 13”, 21);
console.log(“line number 16”, 10);

© GeekySanjay