Skip to the page

Output prediction drills · core

Predicting sync output: hoisting, this, coercion and references

Most non-async output questions test five rules you already know — hoisting and the TDZ, how this is bound at the call site, coercion in + and ==, references vs copies, and built-in quirks like map(parseInt) — so name the rule for each line before you answer.

The notes

What you must know

  • Hoisting: function declarations are fully hoisted; var is undefined; let/const are in the TDZ; calling a var function expression early is a TypeError.
  • this: look at the call site; arrows use the outer this; an extracted method uses the default binding.
  • Coercion: + with a string concatenates; -, * and / convert to numbers; == has a fixed table; objects go through ToPrimitive.
  • References: assignment shares the object; spread copies one level; a mutation is visible through every alias. In a.x = a = {...}, a.x is resolved before a is reassigned.
  • Quirks: typeof null, typeof typeof x, map(parseInt), default sort, 0.1 + 0.2, NaN !== NaN.
  • Answer format: give the output line by line, then the rule; say which line throws and that execution stops there.

The red pen

Common traps: mistake → fix

  • Mistake: Guessing without naming the rule

    Fix: interviewers ask 'why?' for every line.

  • Mistake: Forgetting that a thrown error stops the rest of the script.

  • Mistake: Assuming a.x = a = {...} sets x on the new object

    Fix: the left side was resolved first.

Easy to hard

Questions interviewers ask, easy to hard

  1. Hoisting output.
  2. this in methods, arrows and extracted methods.
  3. Coercion grab-bag.
  4. References and shallow copies.
  5. Built-in quirks: map(parseInt), default sort, typeof.

Practise

Practise with these questions

Your first interview is free

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

Start your free interview