Variables and constants
We use variables to store values, and we use constants to store values that will not change. In JavaScript, we can use the let
keyword to declare a variable and the const
keyword to declare a constant. Before ES6, we could only use the var
keyword to declare variables, but it is not recommended to use it anymore.
Naming conventions
In JavaScript, it is very common to use camelCase to name variables and constants, but other conventions are supported too, such as snake_case and PascalCase. It is also possible to start variables with symbols, but it is not recommended.
There are a few limitations that we need to consider when naming variables and constants:
- Avoid starting with a symbol, such as
$resource
- Don’t start with a number, such as
1variable
- Don’t use spaces, such as
const my variable = 1
- Don’t use reserved words, such as
const const = "
constant"
let versus const
We use let
to declare...