Q1 โ the + operator with mixed types
console.log. Async logs (setTimeout/Promise) appear in real execution order.Answer & why
"12"
2
"33"
"123"
3
1
0
NaN
0
NaN+prefers concatenation when either operand is a string.-always converts to numbers (no string subtraction).1 + 2 + '3'โ left to right:3 + '3'โ'33'.'1' + 2 + 3โ'12' + 3โ'123'.- Unary
+callsToNumber:+true= 1,+null= 0,+undefined= NaN,+[]=+''= 0,+{}= NaN.
Q2 โ loose equality zoo
console.log. Async logs (setTimeout/Promise) appear in real execution order.Answer & why
true
true
false
true
false
false
false
true
true0 == falseโ both โ0 == 0โtrue'' == falseโ'' == 0โ0 == 0โtruenull == falseโ false โnullonly equalsundefinedwith==, nothing else.null == undefinedโ true โ special rule.null == 0โ false โ nullโs only==partner isundefined.NaN == NaNโ false โ NaN is never equal to anything including itself.[] == falseโ'' == falseโ0 == 0โtrue[] == ![]โ[] == falseโ (above) โtrue
Q3 โ typeof gotchas
console.log. Async logs (setTimeout/Promise) appear in real execution order.Answer & why
"object"
"undefined"
"number"
"object"
"object"
"function"
"string"
"undefined"typeof nullโ'object'โ historical bug, never fixed.typeof NaNโ'number'โ NaN is the โNot a Numberโ number.- Arrays and objects both โ
'object'. - Functions โ
'function'(special case). typeof typeof 1โtypeof 'number'โ'string'.typeof undeclaredVarโ'undefined'(not a ReferenceError โtypeofis safe).
Q4 โ increment/decrement operators
console.log. Async logs (setTimeout/Promise) appear in real execution order.Answer & why
5
6
7
7
6a++(post-increment) โ returns current value then increments: returns5,abecomes6.++a(pre-increment) โ increments then returns:abecomes7, returns7.a--(post-decrement) โ returns current value7, then decrements to6.
Q5 โ short-circuit evaluation
console.log. Async logs (setTimeout/Promise) appear in real execution order.Answer & why
"default"
"fallback"
"ok"
1
0
"yes"
"fallback"
0
false||returns the first truthy value (or the last value if all falsy).&&returns the first falsy value (or the last value if all truthy).??(nullish coalescing) โ only falls through onnullorundefined(not0,'',false). This is the key difference from||.
Q6 โ [] + [] and [] +
console.log. Async logs (setTimeout/Promise) appear in real execution order.Answer & why
""
"[object Object]"
"[object Object]"[] + []โ'' + ''โ''(both arrays convert to empty strings).[] + {}โ'' + '[object Object]'โ'[object Object]'.{} + []in a statement context โ{}is parsed as an empty block, then+[]is the expression โ+'' = 0. But({}) + []forces{}to be an object expression โ'[object Object]'.
Q7 โ truthy/falsy surprises
console.log. Async logs (setTimeout/Promise) appear in real execution order.Answer & why
(logs truthy values: "0", [], {}, Infinity, -Infinity)
truthy count: 5Falsy: 0, -0, '', false, null, undefined, NaN โ 7 values. Everything else is truthy, including "0" (non-empty string), [] (empty array), {} (empty object), Infinity, -Infinity.
Q8 โ comparison oddities
console.log. Async logs (setTimeout/Promise) appear in real execution order.Answer & why
false
false
true
false
false
falseThis is the most counterintuitive coercion result. For >, <, >=, <=, null converts to 0. So null >= 0 โ 0 >= 0 โ true. But == has special rules โ null only equals undefined. So null == 0 is false even though null >= 0 is true. This inconsistency is a known JS quirk.
undefined converts to NaN for comparisons โ any comparison with NaN is false. And undefined == 0 is false (only null == undefined).
Q9 โ destructuring output
console.log. Async logs (setTimeout/Promise) appear in real execution order.Answer & why
1 2 [3, 4, 5]
5 20 30
2 4- Rest element collects remaining items into an array.
y = 20โ default values apply only when the property isundefined.yis not in the source โ20.x = 10โxIS in the source (5), so the default is ignored:5.zโ present in source as30.[, second, , fourth]โ skip positions with empty slots.
Q10 โ spread edge cases
console.log. Async logs (setTimeout/Promise) appear in real execution order.Answer & why
[1, 2, 3]
[1, 2, 3, 4]
99Array spread creates a shallow copy โ b is a new array, pushing to it doesnโt affect a. Object spread is also shallow โ copy.nested and obj.nested point to the same object. Mutating copy.nested.y mutates obj.nested.y too.
Q11 โ optional chaining and nullish
console.log. Async logs (setTimeout/Promise) appear in real execution order.Answer & why
"Alice"
undefined
undefined
18
"Alice"?.short-circuits toundefinedwhen it hitsnullorundefinedwithout throwing.address?.cityโaddressisnull, sonull?.cityโundefined(no error).settingsdoesnโt exist โundefined, then?.themeโundefined.?? 18โageisundefined, so nullish coalescing returns18.name ?? 'Anonymous'โnameis'Alice'(not nullish) โ'Alice'.
Q12 โ comma operator and void
console.log. Async logs (setTimeout/Promise) appear in real execution order.Answer & why
3
undefined
undefined
1 9- The comma operator evaluates each operand left-to-right and returns the value of the last one.
(1, 2, 3)โ3. void expressionalways evaluates the expression and returnsundefined. Common use:void 0as a reliableundefined.- In
for (let i = 0, j = 10; ...), the comma in the init and update sections is part of theforsyntax (initializes/updates multiple variables), not the comma operator.
+ string-wins. -/*// always ToNumber. == coerces โ null only equals undefined, NaN equals nothing. ?? is null-or-undefined only (not falsy). ||/&& return operands, not booleans. typeof null === โobjectโ (bug). typeof undeclared === โundefinedโ (safe). Spread is shallow โ nested objects still share references.