What is the output?
let s = 0; for (const k in [5, 6]) s += k; console.log(s);
- 11
- 01
- 0011
- 001
for...in yields the indexes as strings '0' and '1', so += concatenates onto 0.
Play Problem Solving ▸
let s = 0; for (const k in [5, 6]) s += k; console.log(s);