Why is eval ("475957E-8905") == "475957E-8905" true?

I created a program with nodeJs that generate code like

eval("XXXXXX") == "XXXXXX"

It works very well, but in an instant he gave me this:

    eval("475957E-8905") == "475957E-8905"

I tested it with Firebug, and the result true . But I really don't understand why.

Of course, eval("475957E-8905")return 0 but why 0 == "475957E-8905"?

+4
source share
3 answers

There are two parts to this puzzle: floating point numbers and type insensitivity using ==.

-, 475957E-8905 475957 * 10 ^ -8905, ; , 0 - javascript. , eval("475957E-8905") 0.

, .

== , , nodejs ( JavaScript) , .

eval("475957E-8905") 0, "475957E-8905" . , 0. , 0 == 0, .

, , eval("3") == "3" eval("3") == 3 - .

, :

eval("475957E-8905") === "475957E-8905"

false, === javascript true, .

+7

Javascript "475957E-8905" , . , "475957E-8905" 0. , 0 == 0;

:

"475957E-8905" == 0

. eval "475957E-8905" , "475957E-8905" . , , 0.

+3

===, , :

JavaScript , . :

  • , , .
  • , ( ). NaN , NaN. .
  • , .
  • , .
  • Undefined == ( ===). [.. Null == Undefined ( Null === Undefined)]

+2

Source: https://habr.com/ru/post/1527035/


All Articles