2.3 Primitive Types
Hello everyone and welcome to this course we are going to look at primitive types in JavaScript. You've learned how to declare and initiate a variable, now you may be wondering what types of values we can assign to a variable. In JavaScript we have two categories of types: On one side we have primitives also called value typesr and on the other side we have reference types. In this video we will focus on primitives and you will learn more about reference types later in the course. Now, in the category of primitives we have: "String" "Number" "Boolean" "Undefined" "Null" Let's see these elements in action. Here we have declared a variable called "name" and defined it on a string called 'Toto'. We have declared a new variable of type number so we will give it an age set to 25 years. "Number" or literal number. Then we declare a "Boolean" it can be true or false. And we will assign it a value of "true". This value is a "Boolean". Booleans are used in situations where we want to have a certain logic. For example if the order is approved, then it must be shipped, so the value of a boolean variable can be true or false. Note also that the values "true" and "false" are reserved keywords so they cannot be variable names. We will now declare a new variable. If we don't initialize it, by default its value will not be defined, it will be in "undefined". But we can explicitly set it to "undefined". This is the same thing but it is not very common. On the other hand, we have another keyword which has the value "Null". We are going to declare another variable that we will define as "Null". We will give it a value "null". We use "Null" in situations where we want to explicitly delete the value of a variable, for example, we want to present the user with a list of colors, if the user does not have a selection, ColorSelection. In the future if the user selects a color, we will reassign it by giving it a color like red, so we will make a 'red'. He will then have the choice to delete the selection by typing null here. So here are the examples of primitive types of values, in the ES6 version we have another primitive which is a symbol that we will see in a future video. That's it for this video on primitive types in JavaScript, let's meet again for a very next video.