Skip to content

Interview Prep

Frontend Interview Questions

HTML, CSS, JavaScript, the browser, and the frameworks built on them.

12 of 12 Frontend questions shown. Answers are hidden by default — try each one before revealing it.

  1. 1.What is the output order when this code runs in a browser? console.log("A"); setTimeout(() => console.log("B"), 0); Promise.resolve().then(() => console.log("C")); console.log("D");

    Medium

    javascriptevent-loopasync

  2. 2.Given three CSS rules that all match the same element, <button id="submit" class="btn primary">: #submit { color: blue; } .btn.primary { color: green; } button { color: red; } Which color wins?

    Easy

    cssspecificitycascade

  3. 3.const counter = { count: 0, incrementRegular: function () { setTimeout(function () { this.count++; console.log(this.count); }, 0); }, incrementArrow: function () { setTimeout(() => { this.count++; console.log(this.count); }, 0); }, }; counter.incrementRegular(); counter.incrementArrow(); What happens when both methods run (plain non-strict-mode script, in a browser)?

    Hard

    javascriptthisclosuresarrow-functions

  4. 4.A div has width: 200px; padding: 20px; border: 5px solid black; and the default box-sizing: content-box. What is the div's total rendered width, from outer border edge to outer border edge?

    Easy

    cssbox-modellayout

  5. 5.for (var i = 0; i < 3; i++) { setTimeout(() => console.log(i), 0); } What gets logged?

    Medium

    javascriptclosuresevent-loop

  6. 6.In a React list rendered with .map(), why is a stable, unique id generally recommended as the key prop instead of the array index?

    Medium

    reactkeysreconciliation

  7. 7.Explain the CSS box model: what are its four parts, and how does the box-sizing property change how width and height are calculated?

    Easy

    cssbox-model

  8. 8.Explain how the browser's event loop handles asynchronous code. What is the difference between the microtask queue and the macrotask (task) queue, and which one runs first?

    Medium

    javascriptevent-looppromises

  9. 9.When would you reach for CSS Grid instead of Flexbox, and when is Flexbox the better fit? Give a concrete layout example for each.

    Easy

    cssgridflexboxlayout

  10. 10.Explain what a closure is in JavaScript, and give an example of a practical problem it solves.

    Medium

    javascriptclosuresscope

  11. 11.What is event delegation, and why would you use it instead of attaching a click handler to every item in a list?

    Medium

    javascriptdomevents

  12. 12.Explain how JavaScript determines the value of this inside a regular function. Cover the different ways a function can be called, and how arrow functions differ.

    Hard

    javascriptthisarrow-functionsscope

← All interview prep categories