What are Literals, Variables, and Constants in ECMAScript 6 

In this article, We will take a look at what is literals variable and constant? In the previous video will learn how to create your first JavaScript program using Visual Studio code. Before we dive into data type in JavaScript we will take a look from the more important aspect of JavaScript literal variable and constant. Now we will take a step ahead and learn what is variable first.

so will first take a look at what is variable.

What is Variable?

if in the simple form I just wanted to say the variable is just a representation of the value. If you wanted to specify your age and then you wanted to access that value after some time. Then you just need to type the exact value which you type before. But using the variable name you can just refer to that value using the variable name. So we just specify a name for that particular value to access it later or to store it in the memory now whenever you want to access this value you can just specify the name of the variable and then you will get that value.

so this is the example of a variable.

In this example we just created is variable and specify 24 value to it using the equal sign.  and after that, I called console.log method to print the variable value on the console. but this is not the proper way to create a variable. because if someone “use strict” method in the JavaScript then you will get an error message.  the proper way to create a variable in ECMAScript 6 is like this.

The correct way to create a variable in ECMAScript 6

Now let’s move to the next topic constant.

What is Constant?

we are using constant to specify the constant value which cannot be changed after initialization. Constant also hold a value but like variables constant can’t change after initialization. Most programmer use capital letters to declare constant. You are free to choose your own way to declare it. But I strongly suggest you to use capital letters to declare constant. Because it is very helpful to understand which is variable and which is constant.

so this is the example of constant.

Now in this example, we created a constant using const keyword. The const keyword is a reserved keyword by JavaScript so you cannot use this keyword for any other activities like initializing the variable or anything else. after that, we print this constant value on the console using the console.log method.

Let’s move to the next topic Literal.

What is Literal?

Literal means you are specifying a value for a specific identifier directly in the program. During the creation of the program when you specify the value to the specific identifier this value called literal. So this is a small example of Literal.

We created a variable and specify the value using a quotation mark. Using quotation mark we are just specifying string value.  you are free to specify numeric decimal or any value as a little. And after that, we just specify the console.log() method to display tech on the console. We also refer one variable to other using an equal sign.

In short, I just explain everything about literal constant and variables. For more information about this topic Don’t forget to read subsequent articles. That is all for now if you have any question then you can ask me in the comment section. That is al, for now,w will take you back again in the next article.