When does x not equal x?

Viewed 261

In auditing the Javascript version of 'verb', (a NURB library,) I happened across this method:

HxOverrides.cca = function(s,index) {
  var x = s.charCodeAt(index);
  if(x != x) return undefined;
  return x;
};

I'm puzzled by the condition,

if(x != x)

When is this ever True?

1 Answers

In further reading, I discovered the Javascript method, "s.charCodeAt(index)" returns the Unicode value of the (index)th character in string 's'. Specifically:

If index is out of range, charCodeAt() returns NaN.

In the console, I tested:

NaN == NaN

I found this to be false. Therefore, as to the question of:

"When does x not equal x?"

the answer (at least in Javascript,) is:

"x != x when x is NaN (not a number)".

Related