Global-Methods Flashcards
1
Q
isFinite
A
isFinite({mixed} value) => {bool} whether the value is finite #global #safe #alternative - better to use ES6 Number.isFinite, since it won't try and convert the value into a number
value
- can be any data type (since global), isFinite will convert
value
to number or NaN - NaN, Infinity, -Infinity produce false
2
Q
isNaN
A
isNaN({mixed} value) => {bool} whether the value is NaN #global #safe #dontuse - either use `value !== value` or ES6 alternative Number.isNan()
3
Q
parseInt
A
parseInt({str} value, -{num=10} base) => {num} integer representation of value at base of `base`, else NaN if number can't be produced #global #safe BUT base default defined by ES5
value
- string representation, else, converted into string first
- decimal digits are truncated (NOT rounded)
- parseInt() will return prematurely when
value
contains character not recognized bybase
notation, unless the character is the first character, in which case, NaN is returned
4
Q
parseFloat
A
parseFloat({str} value) => {num} decimal number representation of value #global #safe
value
- string representation, else, converted into string first
- parseFloat() will return prematurely when
value
contains characters NOT [0-9.-+e], unless the character is the first character, in which case, NaN is returned.