Summary: Numbers
Review what we learned about numbers in JavaScript.
We'll cover the following
Key points
-
Numbers can be integers, such as , or floats (decimals), such as , although JavaScript doesn’t differentiate between them and just has a single primitive data type of
Number
. -
Numbers can be written in exponential notation, such as
5e6
for five million. -
The arithmetic operations +, -, *, / and % can be applied to any two numbers.
-
It’s possible to change strings to numbers and vice versa.
-
If we try to perform operations between a string and a number, JavaScript will attempt to convert the type to complete the operation. This can cause some inconsistent and unexpected results!
-
A random number between and is returned by the
Math.random()
method.
After the quiz and challenge, we’ll look at how JavaScript deals with collections of values.
Get hands-on with 1400+ tech skills courses.