Number and Math Methods Flashcards
Return boolean check if argument is an integer
Number.isInteger( )
Return a number rounded to a number of decimal places
Why does it return a string?
myNumber.toFixed(numberOfdecimal places )
It returns a string because there is no way to count decimal places in bits (but you can in string indexes). So we have to convert to use .toFixed to convert to string then convert it back to a number.
Returna base 10 number, based off number argument and its number base
Number.parseInt(11, 2)
or just
parseInt()
// expected output
3
Round a number up to the next largest integer
Round a number down up to the next largest integer
Math.ceil(5.5) = 6
Math.floor(5.5) = 5
Return 1 if the argument is positive
Return -1 if the argument is negative
Return 0 if the argument is 0
Math.sign( )
Return the smallest number among the arguments
Return the largest number among the arguments
Do the same but return the max or min element in an array
Math.min() Math.max()
Math.min(…[1, 2]), Math.max(…array)
What does
Math.min()
do?
and/or return?
What happens if an argument is not a number?
The static function Math.min() returns the lowest-valued number passed into it.
Arguemnts are converted to numbers. If any of them are not numbers, it returns NaN.
Math.min()
Math.min(value0)
Math.min(value0, value1)
Math.min(value0, value1, … , valueN)
What does
Math.max()
do?
and/or return?
The Math.max() function returns the largest of the zero or more numbers given as input parameters, or NaN if any parameter isn’t a number and can’t be converted into one.
Math.max()
Math.max(value0)
Math.max(value0, value1)
Math.max(value0, value1, /* … ,*/ valueN)
What does
Math.ceil()
do?
and/or return?
The Math.ceil() function always rounds a number up to the next largest integer.
Math.ceil(x)
What does
Math.floor()
do?
and/or return?
The Math.floor() function returns the largest integer less than or equal to a given number.
Math.floor(x)
What does
Number.prototype.toFixed()
do?
and/or return?
The toFixed() method formats a number using fixed-point notation.
Returns a string with a given number of float points.
toFixed()
toFixed(digits)
What does
Number.isInteger()
do?
and/or return?
The Number.isInteger() method determines whether the passed value is an integer.
Number.isInteger(value)
What does
Number.MAX_VALUE
do?
and/or return?
The Number.MAX_VALUE property represents the maximum numeric value representable in JavaScript.
What does
Number.prototype.toString()
do?
and/or return?
The toString() method returns a string representing the specified Number object.
toString()
toString(radix)
What does
Math.trunc() (not used by internet explorer)
do?
and/or return?
The Math.trunc() function returns the integer part of a number by removing any fractional digits.
Basically it rounds down (unless if it’s got tons of 9s
Math.trunc(x)