Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Salesforce JS-Dev-101 Exam - Topic 1 Question 8 Discussion

Actual exam question for Salesforce's JS-Dev-101 exam
Question #: 8
Topic #: 1
[All JS-Dev-101 Questions]

Given a value, which two options can a developer use to detect if the value is NaN?

Show Suggested Answer Hide Answer
Suggested Answer: C, D

Comprehensive and Detailed Explanation From Exact Extract JavaScript knowledge:

We already know NaN is special: it is not equal to itself.

Check each:

A . value === Number.NaN

Number.NaN is NaN.

NaN === NaN is always false.

This will never be true; cannot reliably detect NaN.

B . value == NaN

NaN == NaN is also always false.

Again, this never detects NaN.

C . isNaN(value)

Global isNaN converts its argument to a number and then checks if the result is NaN.

This can detect NaN, but it may also return true for non-number values that coerce to NaN, such as isNaN('foo').

Regardless, it is a standard way to detect if a value is ''NaN-like'' in JavaScript.

D . Object.is(value, NaN)

Object.is(NaN, NaN) returns true.

This is a strict way to detect a value that is exactly NaN (no coercion).

Therefore, among the given choices, the two viable ways to detect NaN are:

isNaN(value)

Object.is(value, NaN)

________________________________________


Contribute your Thoughts:

0/2000 characters
Annelle
1 day ago
I remember that using isNaN(value) is a common way to check for NaN, but I'm not sure about the others.
upvoted 0 times
...

Save Cancel