Q1 โ Array method chaining output
console.log. Async logs (setTimeout/Promise) appear in real execution order.Answer & why
35
[1, 2, [3, [4]]]
[1, 2, 3, 4]- Odds:
[1, 3, 5]. Squared:[1, 9, 25]. Sum:35. .flat()โ default depth is1: flattens one level only..flat(Infinity)โ recursively flattens all levels.
Q2 โ Array.from edge cases
console.log. Async logs (setTimeout/Promise) appear in real execution order.Answer & why
['h', 'e', 'l', 'l', 'o']
[0, 2, 4]
[1, 2, 3]
[['a', 1], ['b', 2]]Array.from(string)iterates characters.{length: 3}is an array-like; the mapping function gets(value, index).Setremoves duplicates;Array.fromconverts it.- Spreading a
Mapgives[key, value]pairs.
Q3 โ Object.keys/values/entries order
console.log. Async logs (setTimeout/Promise) appear in real execution order.Answer & why
['0', '1', 'b', 'a', 'c']
['zero', 'num', 2, 1, 3]Object key ordering: integer-like keys first (ascending numeric), then string keys in insertion order. '0' and '1' come before 'b', 'a', 'c'. This is a spec-guaranteed order since ES2015.
Q4 โ Symbol as object key
console.log. Async logs (setTimeout/Promise) appear in real execution order.Answer & why
"Alice"
123
["name"]
'{"name":"Alice"}'Symbol keys are hidden from Object.keys, for...in, and JSON.stringify. They only show up in Object.getOwnPropertySymbols() or Reflect.ownKeys(). This makes them useful for private metadata on objects without risking accidental enumeration or serialization.
Q5 โ class private fields
console.log. Async logs (setTimeout/Promise) appear in real execution order.Answer & why
150
SyntaxError: Private field '#balance' must be declared in an enclosing classPrivate class fields (#) are truly private โ accessing them from outside the class is a SyntaxError (caught at parse time, not a runtime error). They donโt appear in Object.keys or via any reflection API.
Q6 โ generator yield and return
console.log. Async logs (setTimeout/Promise) appear in real execution order.Answer & why
{ value: 1, done: false }
{ value: 2, done: false }
{ value: 3, done: true }
{ value: undefined, done: true }yield produces { value, done: false }. return produces { value, done: true }. Once done: true, all subsequent next() calls return { value: undefined, done: true }. yield 4 is unreachable code.
Q7 โ Promise.race and Promise.any
console.log. Async logs (setTimeout/Promise) appear in real execution order.Answer & why
race err: error
any: fastPromise.raceresolves/rejects with the first settled (either fulfilled or rejected).p3rejects immediately โrace err: error.Promise.anyresolves with the first fulfilled (ignores rejections).p3is rejected, thenp2fulfills first at 50ms โany: fast.
Q8 โ Symbol.toPrimitive
console.log. Async logs (setTimeout/Promise) appear in real execution order.Answer & why
42
"hello"
"true"
true[Symbol.toPrimitive](hint) overrides default type coercion. +obj needs number โ hint 'number' โ 42. Template literal needs string โ hint 'string' โ 'hello'. obj + '' โ + with a string uses hint 'default' โ true, then true + '' = 'true'. obj == true โ both use 'default' โ true == true โ true.
Q9 โ Object.assign and spread differences
console.log. Async logs (setTimeout/Promise) appear in real execution order.Answer & why
true
{ a: 1, b: 3, c: 4 }
{ a: 1, b: 2 }
{ a: 1, b: 3, c: 4 }Object.assign mutates the target and returns it โ target === result1 is true. Spread creates a new object โ obj is untouched. Both produce the same merged result (later keys win), but Object.assign is destructive.
Q10 โ class getter/setter
console.log. Async logs (setTimeout/Promise) appear in real execution order.Answer & why
32
212Getters and setters are called with property access syntax, not (). t.fahrenheit triggers the getter. t.fahrenheit = 212 triggers the setter, converting to Celsius internally. The private #celsius would throw SyntaxError if accessed from outside.
Q11 โ forโฆin vs forโฆof
console.log. Async logs (setTimeout/Promise) appear in real execution order.Answer & why
0 1 2 custom (for..in)
10 20 30 (for..of)for...in iterates all enumerable property keys (including inherited ones and added properties like custom). for...of uses the iterator protocol โ for arrays this iterates values only, ignoring non-numeric properties. Never use for...in on arrays.
Q12 โ the multi-concept boss question
console.log. Async logs (setTimeout/Promise) appear in real execution order.Answer & why
[Promise, Promise, Promise]
Promise { <pending> }
sync done
[2, 4, 6]async functions always return a Promise, even when the body is synchronous. arr.map(async โฆ) produces an array of Promises, not values. To get the values, you must await Promise.all(doubled). 'sync done' runs immediately; the Promise.all resolution logs after the current task + microtask queue drains.