JavaScript interview questions
Show answer
varis function-scoped and hoisted with the valueundefined, so it can be used before its line runs.letandconstare block-scoped and sit in the temporal dead zone until declared, so early access throws.constprevents re-assigning the variable, but an object it points to can still be mutated. Preferconst, useletwhen you must re-assign, and avoidvar.Show answer
==converts both sides to a common type before comparing; an empty string converts to the number 0. These coercion rules are hard to remember, so use===, which compares type and value without conversion.Object.isadditionally treatsNaNas equal to itself and distinguishes+0from-0.