I am using Chrome 60.x browser and checking the code isNaN([3]). The result false, but I can’t understand it.
isNaN([3])
false
[3]is an array and it is not empty. I think that [3]this is an array object and it is not a number.
[3]
Otherwise, the result isNaN(["ABC"])is equal true. And one more result isNaN([1,2,3])- true. Therefore, I assume that the javascript engine is an array that changes strength by a number in which the array has one element.
isNaN(["ABC"])
true
isNaN([1,2,3])
Please let me know what happened. isNaNfunction for array parameter.
isNaN
ref1: Why isNaN (null) == false in JS?ref2: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN
[EDIT] Thank you all for your reply.
I understand that javascript parsed the value implicitly before the comparison.
And I found a useful link reading Nina Scholz's answer.Comparison table: http://dorey.imtqy.com/JavaScript-Equality-Table/
When you use it isNaN, it tries to parse your input value into number, and then checks if it is there NaNor not.
number
NaN
See some examples.
For an array with one element, the function Number()returns an object that actually holds the first element as a value (see console.log). For many elements, it returns NaN, so you get the result isNaN→ true.
Number()
console.log
const a = new Number([3]); console.log(`a is ${a}`); console.log(`isNaN(a) - ${isNaN(a)}`); const b = new Number([3,4,5]); console.log(`b is ${b}`); console.log(`isNaN(b) - ${isNaN(b)}`);
, , toString, .
toString
console.log(isNaN([3])); console.log(isNaN('3')); // convert with toString to a primitive console.log(isNaN(3)); // convert to number
Javascript : integer, , . ,
integer
x = increment([3])
x = 4.
x = 4
isNan([3])
false, [3] 3, 3 - . , ["ABC"] integer, isNaN(["ABC"]) = true. , javascript [1,2,3] , ,
3
["ABC"]
isNaN(["ABC"]) = true
[1,2,3]
isNaN([1,2,3]) = true
, Javascript, , , , . ==
==
3 == [3] // returns true
, [0] , [n] n , , .
[0]
[n]
n
[0] == false // returns true [1] == false // returns false
, , isNaN([3])//returns false
isNaN([3])//returns false
Number([3]) === [3] //returns false Number(3) === 3 // returns true
, ===
Source: https://habr.com/ru/post/1685006/More articles:Unexpected behavior when applying a list of lambda functions to another list - pythonHow to upgrade docker in latest version of Amazon linux AMI - dockerCASE SQL Server clause on where inside brackets is sqlNginx on Fedora 26: Failed to create optimal types_hash error message - nginxCan I find out when / if a user has disabled "background activity" in API Level 26 (Oreo)? - androidHow to call asidant Coq confirmation from external software - coqApache Spark: get the number of records per partition - scalaАсимптотическая сложность нарезки/слияния капель - javascriptHow to return ModelState with forbidden web api status - c #How to build linphone android sdk for audio calls only? - androidAll Articles