Multiple choice

Predict the output: function geek() { if(true) { var a = 5; } document.write(a); } geek();

  1. Compilation Error

  2. Runtime error

  3. Nothing will be printed as output

  4. 5

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Variables declared with the 'var' keyword in JavaScript are function-scoped rather than block-scoped. Because 'var a' is declared inside the function 'geek', it is accessible anywhere within that function, even outside the 'if' block where it was defined.