Numbers 16 Flashcards
What are the two kinds of numeric values is JS?
Numbers: 64-bit floating point numbers and are also used for smaller integers
Bigints: represent numbers w an arbitrary precision
Whats the difference between ++/– as a prefix rather than a suffix?
foo++ vs. ++foo
prefix: it adds to foo then returns foo
suffix: it returns foo then adds to it
What are the three ways of converting values into numbers?
Number(x)
+x
parseFloat(x) (avoid this one)
What is the rule for finding NaN in arrays?
There is no rule. You must check to see how each array method handles NaN.
Why should you be careful with decimal fractions in JS?
Internally, js floating point numbers are represented with base 2, which means base 10 decimal fractions can’t always be represented precisely.
What are the four ways of converting Numbers to Integers in js?
Math.trunc chops off anything past deci
Math.floor always rounds down
Math.ceil always rounds up
Math.round rounds up or down