Technically there are two others: Symbol and BigInt. But we don’t have to worry about this as it is used very rarely.
However, we will learn the five primitive types as we go on learning inshaAllah.
First, we will run our code using the Chrome developer tool’s console.
After practicing for a while in the console, we will learn how to write external scripts along with HMTL, inshaAllah.
Anyway, for this tutorial we will stick to console. So, let’s open the console.
- Open Google’s Chrome browser.
- Right-click > Inspect > Console.
Now that you are in the console, try the following operations.
- Add two numbers.
100 + 85
- Subtract two numbers.
100 - 85
- Divide two numbers.
100 / 3
- Try adding decimal numbers.
10.50 + 1.50
- Add two numbers and multiply them by the third number.
(5 + 5) * 10
You just practiced number type of the five primitive types.
Now let’s add Modulo to it. Modulo is commonly used to determine whether a number is even or odd. Modulo gives the remainder of a number.
If you try
19 % 2 in the console, your answer would be
1. If the remainder is 1, it is an odd number. Otherwise, it will become a 0 making it an even number.
The exponent of a number says how many times to use the number in a multiplication.
i.e: 8 to the Power 4 (84) = 4096
8 ** 4 in console and it will return
NaN = Not a Number
When you do an operation with something that is not a number, it returns NaN.
If you divide 0 by 0 that operation will not be valid.
0 / 0 in console and your return value would be
If you prefer to watch, visit my YouTube channel, and don’t forget to subscribe 🙂