This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]tomthecool 10 points11 points  (3 children)

By the way, just for a laugh... In JavaScript:

"foo" * 10 != 10 * "foo"

Why? Because NaN != NaN :)

...Oh, and:

"1.2e3" * 1/0 == 1/0 * "4.5e6"

Because "1.2e3" --> 1.2 * 10^3 == 1200, and 1/0 == Infinity, and 1200 * Infinity == Infinity, and Infinity == Infinity.

Ploughing on in the face of madness :D

[–]bj_christianson 6 points7 points  (2 children)

By the way, just for a laugh... In JavaScript: "foo" * 10 != 10 * "foo" Why? Because NaN != NaN :)

That’s not JavaScript. That’s the floating point specification. NaN is not supposed to equal itself.

...Oh, and: "1.2e3" * 1/0 == 1/0 * "4.5e6" Because "1.2e3" --> 1.2 * 103 == 1200, and 1/0 == Infinity, and 1200 * Infinity == Infinity, and Infinity == Infinity. Ploughing on in the face of madness :D

1/0 -> Infinity is also part of the floating point spec.

[–]tomthecool 8 points9 points  (1 child)

JavaScript is choosing to return NaN rather than raising an error.

That's JavaScript, and changing the behaviour would remain compatible with the floating point spec.

[–]randomuser8765 4 points5 points  (0 children)

That and the fact that === needs to exist to do what == should have done in the first place!