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.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");
Mediumjavascriptevent-loopasync
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?
Easycssspecificitycascade
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)?
Hardjavascriptthisclosuresarrow-functions
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?
Easycssbox-modellayout
5.for (var i = 0; i < 3; i++) { setTimeout(() => console.log(i), 0); } What gets logged?
Mediumjavascriptclosuresevent-loop
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?
Mediumreactkeysreconciliation
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?
Easycssbox-model
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?
Mediumjavascriptevent-looppromises
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.
Easycssgridflexboxlayout
10.Explain what a closure is in JavaScript, and give an example of a practical problem it solves.
Mediumjavascriptclosuresscope
11.What is event delegation, and why would you use it instead of attaching a click handler to every item in a list?
Mediumjavascriptdomevents
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.
Hardjavascriptthisarrow-functionsscope