JavaScript Numbers
Numbers count, measure, and score things.
In JavaScript, whole numbers and decimals share one number type.
Think of one jar that can hold marbles or half marbles.
Whole and decimal numbers
Special number values
Math with numbers
Common gotchas
Writing numbers
Just write the digits.
No quotes. Quotes would make a string.
NaN
NaN means Not a Number.
It shows up when math does not make sense.
Infinity
Dividing by zero can give Infinity.
It means a value too big to finish.
Decimals can be messy
Some decimals are stored in a tiny imperfect way.
That is why 0.1 + 0.2 looks funny.
Number and parseInt
You can turn text into numbers.
Number tries the whole value. parseInt reads from the start.
Tip: Keep money math careful. For learning, toFixed can help you print neat decimals.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.