
- 2 min read
Select one option
1 / 10
console.log(NaN === NaN);
JavaScript Guess the Output #2 - Advanced Concepts — quiz answer sheet, click to expand.
Answer: false
Explanation: NaN is the only value in JavaScript that is not equal to itself. This is a characteristic feature of NaN, to check for it use `isNaN()`.
Answer: true
Explanation: The `!` operator converts its operand to a boolean and then negates it. `[]` is truthy, so `![]` is `false`. The `==` operator then attempts type coercion. `[]` is converted to an empty string `''`, and `false` is converted to `0`. `'' == 0` is `true`.
Answer: ReferenceError
Explanation: This is a temporal dead zone (TDZ) error. `x` inside `foo` is block-scoped due to `let`. When `console.log(x)` is executed, `x` has been declared but not yet initialized, leading to a `ReferenceError`.
Answer: true
Explanation: The `typeof null` returns 'object' (a long-standing bug in JavaScript). `null === null` is true. Both conditions are true, so the result is true.
Answer: 2
Explanation: Objects are assigned by reference. `arr[0]` holds a reference to `obj`. When `obj.a` is modified, the change is reflected in all references to that object, including `arr[0]`.
Answer: 10
Explanation: `parseInt()` parses a string argument and returns an integer. It stops parsing at the first character it encounters that is not a digit or sign, so '10.5 degrees' becomes 10.
Answer: 2
Explanation: When using array literal syntax with commas, each comma implicitly creates an empty slot. `[,,]` has two empty slots (indices 0 and 1), hence a length of 2.
Answer: 1
Explanation: When using the `+` operator with booleans, `true` is coerced to `1` and `false` to `0`. So, `1 + 0` equals `1`.
Answer: 0
Explanation: When `{}` appears at the beginning of a statement, it's often parsed as an empty code block, not an object literal. The expression then becomes `+[]`. The unary plus operator converts the empty array `[]` to a number, which is `0`.
Answer: [object Object]
Explanation: When the `+` operator is used with an array and an object, JavaScript attempts to convert them to primitive values. `[]` converts to an empty string `''`. `{}` converts to the string `'[object Object]'`. The `+` operator then performs string concatenation.