Number Flashcards
Attributes
Primitive data type / immutable Contains properties & methods 64 bit float #safe
Instantiation
// literal 1 // constructor; arg is converted into number, else NaN Number(1) // primitive new Number(1) // object
Properties
Number.MAX_VALUE
=> highest number prior to becoming infinity
#safe
#static
Number.MIN_VALUE
=> lowest number prior to becoming 0
#safe
#static
.NaN
=> NaN
#safe
#static
Number.NEGATIVE_INFINITY
=> -Infinity
#safe
#static
Number.POSITIVE_INFINITY => Infinity #safe #static #examples: Number.POSITIVE_INFINITY === Infinity Number.NEGATIVE_INFINITY === Infinity * -1 Number.POSITIVE_INFINITY === -Infinity * -1 NaN === -Infinity * 0 NaN === -Infinity / -Infinity
Methods (?)
.toExponential —exponential form of number
.toFixed —number with fixed-point notation
.toPrecision —number in exponential or numeric form
.toString —number @ base of ?
.valueOf —convert object into primitive
Global methods related to numbers (4)
isFinite —determine if value could be a finite number
isNaN —determine if value is NaN
parseInt — convert value into integer from base
parseFloat —convert value into float
What is NaN
NaN — “Not a Number”, comes from Number.NaN, and is the result of an operation that failed to produce a number—such as Math.sqrt(-1)
What makes NaN totally unique?
NaN is the ONLY javascript data type that cannot use ===
(since it always evaluates to false). Example
NaN === NaN
=> false