yoklainterview sim

JavaScript Frontend Interview Questions

450 verified JavaScript Frontend interview questions — solve with answers, learn from explanations, test yourself in a real simulation.

Try the real simulation →

Sample questions

Javascript Async ConcurrencyDifficulty 1
A JavaScript Promise can be in one of three states. Which set correctly names them?
  • astarted, waiting, finished
  • bpending, fulfilled, rejected
  • copen, resolved, closed
  • dqueued, running, done
Explanation:A Promise starts as pending, then settles exactly once into either fulfilled (a value is available) or rejected (an error occurred). Once settled it never changes state again.
Javascript Async ConcurrencyDifficulty 1
What does an async function always return when called, regardless of what its body returns?
  • aThe raw value from return, unwrapped
  • bundefined unless you explicitly return a Promise
  • cA Promise that resolves to the returned value
  • dNothing — you must attach a callback for the return value
Explanation:Calling an async function always produces a Promise. If the body returns a plain value, that value becomes the resolved value of the returned Promise; if it returns a Promise, the outer Promise adopts its state.
Javascript Async ConcurrencyDifficulty 2
console.log('start');
setTimeout(() => console.log('timeout'), 0);
Promise.resolve().then(() => console.log('promise'));
console.log('end');

What is logged, in order?
  • astart, end, promise, timeout
  • bstart, promise, end, timeout
  • cstart, end, timeout, promise
  • dstart, timeout, end, promise
Explanation:All synchronous code runs first (start, end). Then the microtask queue (the .then callback) drains completely before the event loop moves to the macrotask queue, so promise logs before timeout even though setTimeout was scheduled first.
Javascript Async ConcurrencyDifficulty 2
console.log('a');
Promise.resolve(42).then((v) => console.log('b', v));
console.log('c');

What is logged, in order?
  • aa, b 42, c
  • bb 42, a, c
  • ca, c, b, then 42 separately
  • da, c, b 42
Explanation:Promise.resolve(42) is already fulfilled, but its .then callback is still scheduled as a microtask — it never runs synchronously. So the remaining synchronous line (console.log('c')) executes first, and b 42 logs only after the current script finishes.
Javascript Async ConcurrencyDifficulty 1
Where can the await keyword be used at the top level of a function body?
  • aInside any function, as long as a Promise is involved
  • bOnly inside a function declared async (or in a module top-level await context)
  • cOnly inside .then() callbacks
  • dAnywhere, it works like a synchronous keyword by default
Explanation:await is only valid inside a function marked async, or at the top level of an ES module that supports top-level await. Using it in a regular function is a syntax error.
Javascript Async ConcurrencyDifficulty 2
Promise.resolve(1)
  .then((v) => v + 1)
  .then((v) => v * 10)
  .then((v) => console.log(v));

What is logged?
  • a1
  • b2
  • c20
  • d11
Explanation:Each .then receives the value returned by the previous one: 1 → (1+1)=2 → (2*10)=20 → logged. Returning a plain value from .then passes it forward to the next .then in the chain.

Test yourself against the 2925-question Frontend bank.

Start interview