Variables in JavaScript tend to confuse people.
They are one of those all-time JavaScript mysteries.
We have 3 types of variables in Javascript: const, let, and var;
To define a const variable put a keyword const followed by a variable name and pass in the initial value.
What’s specific to const variables is that you have to assign the initial value and you can’t add new values after that. Also, you can not use it before it’s declared.
To define a let variable use the same approach with the let keyword.
Also, it’s only accessible within the code scope where it’s created like const and you can’t use it before it’s declared.
However, you don’t have to put an initial value and you can update it afterward.
To declare a var variable you use the var keyword.
But if you try to use it before it’s declared you will not get an error. Also code block like if statement doesn’t create scope for var variables.
Linkedin: link / slobodan-gajic
Portfolio: https://bobangajicsm.github.io/portfo...
Twitter: / _slobodangajic_