What will be the output of the following code: console.log(a); var a = 10;
1Times asked
May 2026Last seen
May 2026First seen
💡 Model Answer
In JavaScript, variable declarations using var are hoisted to the top of their scope, but the assignments are not. The code is effectively interpreted as:
var a;
console.log(a);
a = 10;
When console.log(a) runs, the variable a exists but has not yet been assigned a value, so its value is undefined. Therefore, the output will be undefined. After the console.log statement, a is assigned the value 10. This behavior demonstrates the difference between declaration hoisting and initialization.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500