โ† JavaScript
#3 most askedVery commonEasyScope & closures

let vs const vs var

๐Ÿข Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.
I was asked this

What are the differences between var, let and const? Which should you use by default?

๐Ÿ”ฎ Predict the output

for (var i = 0; i < 3; i++) {
  setTimeout(() => console.log("var", i), 0);
}
for (let j = 0; j < 3; j++) {
  setTimeout(() => console.log("let", j), 0);
}

๐ŸŽค Answer it out loud, then check yourself

Say your answer as if the interviewer is listening (30โ€“90 seconds). Then reveal what a strong answer covers and tick what you said.

    Answer out loud first, then compare.
    Want to rehearse it?
    Answer this to the AI interviewer and get a verdict โ†’