Shankar Yadav’s Post

One JavaScript interview question that still confuses many developers: What will be the output? for (var i = 0; i < 3; i++) { setTimeout(() => console.log(i), 1000) } Output: 3 3 3 Why? Because var is function-scoped and the loop finishes before the callback executes. Correct version: for (let i = 0; i < 3; i++) { setTimeout(() => console.log(i), 1000) } Output: 0 1 2 Understanding closures and scope is critical for writing reliable JavaScript. This concept appears frequently in frontend and Node.js interviews. What other tricky JavaScript questions have you seen in interviews? #javascript #frontenddeveloper #webdevelopment #codinginterview

can u say this one without executing it console.log("Starting  ") let number = 0 console.log("Initial value ", number) setInterval(() => {     number += 1     console.log("Current value = ", number) }, 1000) setTimeout(() => {     console.log("After 5 seconds")     while (true) {     } }, 5000)

Hello, it would be great if you could share your interview experience here: https://l0ser.vercel.app/ so that juniors can learn and be motivated.

See more comments

To view or add a comment, sign in

Explore content categories