This will be part of a 4 series tutorial to help you understand the nitty-gritty of the topic. Here, we will discuss Variables, Data types, and Arithmetic Operations
For a short example:
let thisVariable = "this value"
thisVariable and the
= sign tells the JS engine again that the value we want the variable to hold is
let myBestFood = "rice"
There are other keywords that are used to define or declare variables, we also have
var. Their purposes are differ.
const keyword is used to define or declare variables whose value cannot be changed.
var keyword is used to declare variables whose value can be accessed or changed from anywhere in your code.
const myHeight = 181 //this variable cannot be reassigned another value
var myBagPackColor = "green" //this variable's value can be accessed anywhere in the program
Note: Variables cannot have space!
Notice the value of the variable below:
let myBagPackColor = "green" // this value is a string
"green" in quotes("") is a string data type.
123 is a number data type.
false are regarded as Boolean data types. They are the only kind of data that can be called Booleans.
There is also
undefined which is an absence or data and type. And there is
null which is what is used to denote that there is no value. They can also be assigned to variables. example:
let unknownVariable = undefined var something = null
All the above mentioned data types are known as Primitive Data types. That is, String, Number, Boolean, Undefined, and Null.
let firstNumber = 12 let secondNumber = 20 let result = firstNumber + secondNumber //This will give 32
Pretty straight, right?
let firstNumber = 12 let secondNumber = 20 let result = secondNumber - firstNumber // This will give 8
Same goes for multiplication using (
*), division using (
/) and also modulus (remainder), using (
We've covered quite a bit here!
Variables help us hold values in memory. This values can have different data types some can be string, number, booleans or even null and undefined. The number types can be used to perform arithmetic operations.