Skip to content

Instantly share code, notes, and snippets.

@1kohei1
Created January 12, 2019 17:20
Show Gist options
  • Save 1kohei1/93702960df793c91aa0f64b3c20ec597 to your computer and use it in GitHub Desktop.
Save 1kohei1/93702960df793c91aa0f64b3c20ec597 to your computer and use it in GitHub Desktop.
void 2; // undefined
void 'abc'; // undefined
void function() {}; // undefined
void undefined; // undefined
void null; // undefined
void {}; // undefined
void true; // undefined
void false; // undefined
// NaN means "Not a Number", however the type of NaN is a "number"
var a = 'abc' * 2; // NaN
typeof a; // number
typeof a === 'number'; true
// NaN means "invalid number"
// All operations on NaN also returns NaN
NaN * 2; // NaN
NaN * 'abc'; // NaN
// NaN is the only value which cannot be equal to NaN
NaN == NaN; // false
NaN === NaN; // false
// This is clearly defiend in the spec. https://www.ecma-international.org/ecma-262/9.0/index.html#sec-strict-equality-comparison
/**
* If Type(x) is Number, then
* a. If x is NaN, return false.
* b. If y is NaN, return false.
*/
// There is also Infinity to represent the Infinity.
// You can get Infinity by number / 0 => Infinity
// Negative infinity is negative number / 0 => -Infinity
Infinity + 3; // Infinity
Infinity * 3; // Infinity
Infinity / 3; // Infinity
Infinity - Infinity; // NaN Since we cannot represent that as a number!
Infinity / Infinity; // NaN Since we cannot represent that as a number!
// There is also positive and negative 0.
0 / 3; // 0
0 / -3; // -0
0 * -3; // -0
// Why is negative 0 necessary?
// The number can mean another piece of information such that speed. And in such case, the sign means which direction they are moving. So if we remove the sign on 0, it loses the such information which all the other value have.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment