-
Create a Variable: letStudy/JavaScript 2020. 4. 29. 09:54
Create a Variable: let
As mentioned in the previous exercise, the let keyword was introduced in ES6. The let keyword signals that the variable can be reassigned a different value. Take a look at the example:
let meal = 'Enchiladas'; console.log(meal); // Output: Enchiladas meal = 'Burrito'; console.log(meal); // Output: Burrito
Another concept that we should be aware of when using let (and even var) is that we can declare a variable without assigning the variable a value. In such a case, the variable will be automatically initialized with a value of undefined:
let price; console.log(price); // Output: undefined price = 350; console.log(price); // Output: 350
Notice in the example above:
- If we don’t assign a value to a variable declared using the let keyword, it automatically has a value of undefined.
- We can reassign the value of the variable.
'Study > JavaScript' 카테고리의 다른 글
The switch keyword (0) 2020.04.29 String Interpolation (0) 2020.04.29 Create a Variable: var (0) 2020.04.29 Properties (0) 2020.04.28 Data Types (0) 2020.04.28