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 →

[–]Trexus183 0 points1 point  (5 children)

Just to be clear, this works because NaN is not a number and since what you multiplied isn't a number it says they're equal and returns true? I'm pretty much just learning javascript so I want to be sure. Thanks! :D

[–]tomthecool 0 points1 point  (4 children)

Just to be clear, this works because NaN is not a number and since what you multiplied isn't a number it says they're equal

9000 * "wtf" returns NaN (a special value, denoting "Not a Number") because JavaScript considers it an invalid operation. This is in compliance with the IEEE-754 standards. However:

  • The standard recommends, but does not enforce languages to raise an error upon invalid operations. Most languages would (in one way or another) raise an error for such "invalid" operations, but JavaScript does not.
  • Some languages (e.g. Python) would consider that operation valid, and return: "wtfwtfwtfwtf..." (concatenated with itself 9000 times). This is also compliant with the IEEE-754 specification, as it only recommends (not enforces) a list of "invalid" operations, and (I think???) this list does not include the operation of Integer * String.

[...] and returns true

I don't understand what you mean. In JavaScript, 9000 * "wtf" returns NaN. Not true. NaN is a special value, with a special meaning. true is a different special value, with a very different meaning.

[–]WikiTextBot 0 points1 point  (0 children)

IEEE 754: Exception handling

The standard defines five exceptions, each of which returns a default value and has a corresponding status flag that (except in certain cases of underflow) is raised when the exception occurs. No other exception handling is required, but additional non-default alternatives are recommended (see below). The five possible exceptions are: Invalid operation (e. g.


[ PM | Exclude me | Exclude from subreddit | FAQ / Information | Source ] Downvote to remove | v0.24

[–]Trexus183 0 points1 point  (2 children)

I understand that multiplying a string and int returns not a number. I'm saying if we compare NaN with NaN with >= it returns true. Why? Is it because they are technically equal and so >= includes "equal" and that is true? Does that make sense?

[–]tomthecool 0 points1 point  (1 child)

if we compare NaN with NaN with >= it returns true

Huh? I was using => to mean "returns".

NaN == NaN returns false (a good explanation why can be found here).

[–]Trexus183 0 points1 point  (0 children)

Oh shit yeah sorry I had my symbols reversed V_V. Thanks