DEV Community

newAlicorn
newAlicorn

Posted on

Intro to JavaScript Variables

1. Using reserved keywords
In JavaScript, we use one of the three reserved keywords - var, let, const - to declare and assign a variable.
Alt Text

Note:
(1). If the const value is an array or an object, we can modify the properties or the elements.
(2). When to use:
DO NOT use var
Use let for variables where the value may change
Use const whenever possible

2. Without reserved keywords
If we assign a variable without using any of the keywords, the variable will be a global variable. We should avoid defining global variables because they can be accessed and changed EVERYWHERE.

Top comments (0)