Note 3 : Variable , Constant , Primitive Type and Dynamic Types.
Variable :
- It is one of the most fundamental core concepts in any programing language. We use variables to store data temporarily. so we store data somewhere and give that memory location a name and with the name, we read the data and use the location in the future.
- so before ES6, we use the var keyword to declare any variable. but now going forward from ES6 the best practice is to use let or const keyword.
There are some rules while declaring a variable.
- Can't be reserved keyword.
- Should be meaningful.
- can't start with a number.
- can't contain any space or any other special symbol or hyphen(-).
- There are case sensitive.(user and USER are different).
Constant :
- There is a certain scenario when we don't want to change the value of any variable because it can create all kind of bugs which we don't want in our project. or in a simple way, I can say if I want a variable whose value I want to change the future anywhere so then I can use const keyword.
- The best example I can assume the value of PIE will always be 3.14. so it is ok to use const here. so after creating value with const if anyone will try to change the value the error will occur and it will not allow changing the value.
Primitive Type :
- So basically in JavaScript, we have 2 categories of type. one side we have primitive and also known as value types. and another type is Reference Types.
Dynamic Types:
- One thing JavaScript separates from any other languages Is its dynamic nature. we can say it is a dynamic language.
- we have 2 types of programming languages. 1)Static language. 2) Dynamic Language.
- In Static language, if we set any variable value it will set the same and it will not be changed in the future. but in the dynamic programming language like JavaScript, it can be changed in RunTime.
Comments
Post a Comment