Interview Q&A / JavaScript
JavaScript interview questions
Closures, the event loop, this, promises and the core language questions every frontend round asks.
Prefer rapid revision? Practise JavaScript short interview answers →
- Why does [10, 9, 1].sort() give [1, 10, 9], and how do you sort numbers correctly?
By default sort converts items to strings and compares them in dictionary order, so "10" comes before "9". Pass a comparator like (a, b) => a - b to sort numbers. Note that sort changes the original array.
BeginnerQuick answer1 min read