This question already has an answer here:
In Eloquent JavaScript rev.3 (http://eloquentjavascript.net/02_program_structure.html)there is a code snippet:
let theNumber = Number(prompt("Pick a number"));
if (!Number.isNaN(theNumber)) {
console.log("Your number is the square root of " +
theNumber * theNumber);
}
Here is what I understand:
First: create a variable and assign the window.prompt method to it. Use the Number wrapper object to convert the string to a number.
Second: Create a conditional and check if the the variable is NaN (not a number) If no (the ! operator), log the square root in the console.
What I don't understand is the meaning of !Number.isNaN... Why is the author doing it that way?
Isn't it enough to just write the condition as:
if (!isNaN(theNumber) {...}
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire