What is JavaScript Variables? Defference between Let, Var and Const Variables

JavaScript variables are the containers in JavaSscript in which we can store any type of data. Javascript variables are also called the storage of the program.


What is JavaScript Variables? Defference between Let, Var and Const Variables

Difference between Let, Var, and Const JavaScript Variables

JavaScript variables are the most important concept of JavaScript. Without the concept of Javascript variables, you can not become a javascript developer.


Like Bootstrap, JavaScript also has containers that store data are used to store data. Javascript containers are called variables. Any type of data can be stored in these variables, the stored data may be string-type data boolean-type data, etc. 


As you all guys know JavaScript is a scripting-based dynamic language. Dynamacyy language means by using Java script we can change data at a run time. If you want to read a simple introduction to javascript then must read, Simple Introduction to JavaScript. JavaScript variables are very important to make the JavaScript program dynamic.


If you are a junior developer or student and don't know about JavaScript variables, then this article is for you. In this article, I will describe what is and I will tell describe about Let, Var, and Const Variables.


What is JavaScrpt Variables?

JavaScript variables are the containers of JavaScript that are used to store some data. The data that is stored in javascript variables can be changed at any time. In simple words, we can change the stored data of a variable during the execution of our program.


JavaScriopt variables are the names of the locations where we store some data. JavaScript variable is also called the basic storage location of some data.


There are three types of javascript variables: 

  • Let
  • Var
  • Const

Var variable in JavaScript

Var is a special keyword in Java that is used to define the variable in JavaScript. The var keyword is written with the name of the variable that we want to declare.


Below is a method to declare var variable:

<script>

    var VariableName = "Some data that you want to store"

    console.log(VariableName);

</script>

 

var: var is a keyword that shows the type of the variable. 


VariableName:    It is the variable name. This will be the variable name in which you will store any of your content. You can change the name of the variable at any time.


In the var variable, we can change and declare the var variable again and also we can change the value of the var variable. In simple words if we declare a var variable at one time, the next time when we declare a var variable we can override its value. There are some rules for writing variable names. Below are a few rules for writing a variable name:

  • We can not add space between the variable name(Variable Name). We can use the underscore(_) between the variables to declare the variable name(Variable_Name). Also, we can use a dash(-) between the variable name(Variable-Name).
  • We can not add digits at the start of the variable name (11VariableName). We can add digits at the end of the variable name like VariableName11.

=:(Operator):    The equal(=) sign is an operator that shows the value of the declared viable is equal to some data.


Let Variable in JavaScript

Let variable is also a variable in javascript. In the let variable, we can not declare the same name variable multiple times. We can declare the var variable just once time. If declare a let variable multiple times then your code shows a javascript error and does not execute your javascript code. 


The main difference between let and war is, that in the var variable, we can declare the same variable multiple times but in the let variable we can not declare the same variable multiple. In simple words, we can override a private value of the let variable but can not declare the same variable again.


<script>

    let VariableName = "Some data that you want to store"

    console.log(VariableName);

</script>

 

Const Variable in JavaScript         

Consent is the third variable type of javascript. The const variable is derived from the world constant, so the const variable means that this variable is a constant. A constant is a term whose value can never change.

<script>

    const VariableName = "Some data that you want to store"

    console.log(VariableName);

</script>

Post a Comment

Previous Post Next Post