Variables are used to store data on a computer.
There are different type of data that you can store in a variable, the following are different types of data types:
- string
- number
- boolean
- object
- null
- undefined
- symbol
- BigInt
- function
Variables are accessed with a label, not with the data itself.
Let me explain the above point, firstly to create a variable you need to use the "var" keyword followed by a name for the variable and then assigning a value to it from any of the above data types.
Ex: var count = 20;
Here "count" is called the label. When we need to use the variable later we use its label to get the value stored in it.
Here we have stored a number 20 in the variable with a label count.
Hope this has helped you understand how to use variables.
Top comments (4)
Sorry No offense, Am I the only who using let & const in 2020? Why still using "var"? To be honest, I'm also a newbie although, just let me know what is the core differences between them using in 2020?
Yes let and const are part of es5 and they are used in modern JS code, however, there is still a lot of old code written with var.
I am sharing the basics of variables from Vanilla JS.
Well, const is mainly used to prevent reassigning and overriding its value.
let is used mostly in loops because the counter value has to be reassigned every time.
Types - you missed
BigInt
andFunction
Hi Jon,
Thanks for correcting me, I have added them now.
I appreciate your feedback.