Skip to the page

Output prediction · Write code

Hoisting output

The interviewer asks

Output, line by line?

console.log(a); var a = 1;
foo(); bar();
function foo() { console.log('foo'); }
var bar = function () { console.log('bar'); };
console.log(b); let b = 2;

Then

Follow-ups the interviewer asks next

  1. Which line stops execution?
  2. What if bar were an arrow function under const?

The answer

What a strong answer covers

  • undefined, foo, then TypeError: bar is not a function, and execution stops
  • If it continued: ReferenceError: Cannot access 'b' before initialization

The red pen

Common traps

Avoid:answering undefined for bar().

Practise this out loud

Say your answer out loud to an AI interviewer that follows up, and get a score for it.

Practise by voice

Practise questions like this out loud

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview