Select Page
Javascript numbers include integers and floats.
You can concatenate numbers, even if they are enclosed in quotes, but using addition does not add the numbers.
Example:

a = 5
b = “7” / b is a string

You can find the type of a variable by using this function:
typeof(b) / outputs “string”
typeof(a) / outputs “number”

a * b =35
a /b = .714…
a – b = -2
a + b = 57 / Note it concatenated them when using addition

“10” * “4” = 40
“10” + “4” = 104

Helper Methods

Math.round(20.5) / rounds up to 21
Math.round(20.3) / round down to 20
Math.floor(20.9) / outputs 20
Math.ceil(20.01) / outputs to 21

Math.random() -gives a random number between 0 and 1

Along with addition, subtraction, multiplication, and division, we also have 2 additional javascript operators.

Two Additional Operators:

Let’s take a bag of cookies. There are 20 cookies. There are 3 kids. So how many cookies does each kid get? 6.

const cookies = 20;
const kids = 3;
const eachKidGets = Math.floor(cookies / kids);
console.log(`Each kid gets ${eachKidGets}`);

So what about the 2 cookies that are left?
cookies % kids / this would output 2 (the remainder)

const leftoverCookies = (cookies % kids);

Not a Number is NaN (Not a number)
typeof(NaN) outputs “Number”
This just happens if you try and divide a number by a string, for example, 10 / “dog” would produce NaN
Remember though, if a number is inside a string, it will convert that string to a number, so 10 / “5” would output 2

**
When using **, this means to the power of.
For example, 5**3 is the same as 5X5X5, which outputs 125