An Interest In:
Web News this Week
- March 21, 2024
- March 20, 2024
- March 19, 2024
- March 18, 2024
- March 17, 2024
- March 16, 2024
- March 15, 2024
Var VS Let in Javascript
In Javascript, you can declare a variable using Var or let BUT there is an inconvenient, dont worry, I will give you context.
Some years ago(2015) Javascript changed. Var had a global scope before 2015, BUT with ecmascript6 it changed because We can use Let to declare a variable.
You shouldnt use Var because it is considered a bad practice , It can get you into a value reassignment problem.
Example:
In this example I created a variable using var and printed on console three times to show you this
You can see that the variable var was added to windows global object.
BUT if you create a variable using LET, you wont have that problem, and the variable LET could be a local or global variable.
I hope I have helped you by solving this question and You have saved time.
I look forward to your comments, have a nice day. =D
Original Link: https://dev.to/rych182/var-vs-let-in-javascript-2l47
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To