Master JavaScript.
- Topic 6
var vs let vs const ๐คฏ
Explained: ๐งต
- Topic 6
var vs let vs const ๐คฏ
Explained: ๐งต
Declaration of var vs let vs const
We can declare a JavaScript Variable:
- Using var.
- Using let.
- Using const.
We can declare a JavaScript Variable:
- Using var.
- Using let.
- Using const.
So, returning to the var vs let vs const:
The main difference between var, let, and const is:
- Variables declared with the "var" keyword are function scoped.
- Variables declared with "let" and const are block-scoped.
The main difference between var, let, and const is:
- Variables declared with the "var" keyword are function scoped.
- Variables declared with "let" and const are block-scoped.
So let us understand what we mean by Blocked-Scope and Function Scope first.
- Block scoped variables:
A block-scoped variable means that the variable defined within a block will not be accessible from outside the block.
- Block scoped variables:
A block-scoped variable means that the variable defined within a block will not be accessible from outside the block.
- function scoped variables:
A function scoped variables mean that the variables defined within the function will not be accessible from outside the function.
A function scoped variables mean that the variables defined within the function will not be accessible from outside the function.
The main issue with the "var" keyword is that when you declare a variable with the "var" keyword, its scope is not limited to the block in which it is defined.
We can also access that variable from outside of that block.
We can also access that variable from outside of that block.
If you found this thread useful,
1. Do Retweet the first tweet.
2. Follow
@CodeMarch
for the amazing content on Javascript & React.
1. Do Retweet the first tweet.
2. Follow
@CodeMarch
for the amazing content on Javascript & React.
Loading suggestions...