K
K
Kerrik Sun2021-06-27 19:20:50
JavaScript
Kerrik Sun, 2021-06-27 19:20:50

Why doesn't the method of the Number object run in this case?

An object 's methodNumber isNaN must determine whether the value is NaNor not.

let a = 10;
console.log(a.isNaN()); //a.isNaN is not a function

Why is this method not found and just an error is thrown? Or I'm not looking at the methods there at all ...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Pavel Shvedov, 2021-06-27
@Eva25

The isNaN method, which is listed in the list of Number methods, is a method of the Number itself, and not an instance, so you need to call it:
Number.isNaN(a)

A
Alexey, 2021-06-27
@Azperin

This is just a global function for checking for NaN, in ec6 it is also a static method of the Number.isNaN constructor.
It does not appear in the number prototype

A
Alexander, 2021-06-27
@Aleksandr-JS-Developer

In general, a function can be used and not as a method.
Like this:isNaN( value )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question