Exam JS-Dev-101 Topic 2 Question 56 Discussion

Actual exam question for Salesforce's JS-Dev-101 exam
Question #: 56
Topic #: 2
Given a value, which three options can a developer use to detect if the value is NaN?

Suggested Answer: C,D,E Vote an answer

In JavaScript, NaN has some special properties:
NaN is not equal to anything, including itself.
Equality operators (==, ===) do not work for detecting NaN.
Check each option:
A . value === Number.NaN
Number.NaN is just NaN.
But NaN === NaN is always false.
So this expression is never true and cannot be used to detect NaN.
B . value == NaN
Same issue. NaN == NaN is always false.
So this also never detects NaN.
C . Object.is(value, NaN)
Object.is is a more precise equality comparison method.
It treats NaN as equal to NaN: Object.is(NaN, NaN) is true.
So Object.is(value, NaN) is a valid way to detect NaN.
D . value !== value
Because NaN is the only JavaScript value that is not equal to itself,
value !== value is true only when value is NaN.
This is a classic trick for NaN detection.
E . Number.isNaN(value)
Number.isNaN is the recommended modern way to check if a value is NaN without coercion.
It returns true only if value is actually the number NaN.
Therefore, the three correct ways are:
Object.is(value, NaN)
value !== value
Number.isNaN(value)

by Joa at Jul 25, 2026, 10:12 AM

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
Nick name: Submit Cancel
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

0
0
0
10