Question 3Easy
What is the output?
console.log(NaN === NaN, Object.is(NaN, NaN));
- false, true
- true, true
- false, false
- true, false
Answer: A. false, true
Explanation
NaN is never === to anything, including itself, but Object.is considers NaN identical to NaN.
Step-by-step solution
- === follows IEEE rules: NaN !== NaN.
- Object.is uses SameValue, so NaN matches NaN.
Why the other options are wrong
- B. NaN is not strictly equal to itself.
- C. Object.is treats NaN as the same value as NaN.
- D. The results are the other way round.
Tip: Use Number.isNaN(x) to test for NaN.
Question 5Medium
What is the output?
console.log([1, 2, 3] + [4]);
- 1,2,34
- 1,2,3,4
- [1, 2, 3, 4]
- 10
Answer: A. 1,2,34
Explanation
+ converts both arrays to strings ("1,2,3" and "4") and concatenates them.
Step-by-step solution
- The + operator, when used on two arrays, first converts each array to a string.
- [1, 2, 3] becomes the string "1,2,3", and [4] becomes "4".
- These two strings are then concatenated, giving "1,2,34".
Why the other options are wrong
- B. "1,2,3,4" would require + to somehow merge the arrays' contents with a comma between the last elements, but + just concatenates the two already-stringified arrays directly.
- C. [1, 2, 3, 4] would be the result of using the array's .concat() method instead of +, which does something entirely different.
- D. 10 would only make sense if + tried to add array lengths or something similarly unrelated to how arrays stringify.
Tip: To actually combine arrays, use arr1.concat(arr2) or the spread syntax [...arr1, ...arr2], never +.
Question 7Medium
What is the output?
console.log(+'', +' ', +'\n', +[], +{});
- 0, 0, 0, 0, 0
- 0, 0, 0, 0, NaN
- NaN, NaN, NaN, 0, NaN
- 0, 0, 0, NaN, NaN
Answer: B. 0, 0, 0, 0, NaN
Explanation
Empty or whitespace-only strings and the empty array convert to 0; a plain object becomes "[object Object]" and then NaN.
Step-by-step solution
- Whitespace-only strings trim to empty, which is 0.
- +[] goes via "" to 0.
- +{} goes via "[object Object]" to NaN.
Why the other options are wrong
- A. An object converts to NaN.
- C. Blank or whitespace strings convert to 0.
- D. An empty array becomes "" and then 0.
Question 8Medium
What is the output?
console.log(typeof NaN, typeof [], typeof function(){}, typeof Symbol());
- number, array, function, symbol
- number, object, function, symbol
- number, object, object, symbol
- NaN, object, function, symbol
Answer: B. number, object, function, symbol
Explanation
NaN is a number, arrays are objects, functions report "function", symbols report "symbol".
Step-by-step solution
- typeof NaN is "number".
- Arrays are objects.
- Functions give "function", symbols "symbol".
Why the other options are wrong
- A. typeof has no "array" result.
- C. Functions report "function".
- D. typeof NaN is "number".
Tip: Use Array.isArray to detect arrays.
Question 10Hard
What is the output?
console.log(1 < 2 < 3, 3 > 2 > 1);
- true true
- false true
- true false
- false false
Answer: C. true false
Explanation
Comparisons are evaluated left to right. 1 < 2 is true, and true < 3 becomes 1 < 3 (true). 3 > 2 is true, and true > 1 becomes 1 > 1 (false).
Step-by-step solution
- Comparison operators like < and > are evaluated strictly left to right, with no special 'chaining' behaviour like in math.
- For 1 < 2 < 3: first 1 < 2 evaluates to true, then true < 3 is evaluated, where true converts to 1, so 1 < 3 is true.
- For 3 > 2 > 1: first 3 > 2 evaluates to true, then true > 1 is evaluated, where true converts to 1, so 1 > 1 is false.
Why the other options are wrong
- A. true true would mean both expressions behave like mathematical chained inequalities, but JavaScript doesn't support that; it evaluates strictly pairwise.
- B. false true reverses which expression is actually true and which is false.
- D. false false would mean both end up false, but the first expression (1 < 2 < 3) does evaluate to true.
Tip: Never chain comparisons like a < b < c in JavaScript expecting mathematical range-checking - write (a < b) && (b < c) instead.