Back to Course

Introduction to JavaScript

0% Complete
0/0 Steps
  1. JavaScript: Basics
    9Topics
    |
    10 Quizzes
  2. JavaScript: Variables
    9Topics
    |
    10 Quizzes
  3. JavaScript: Conditional Statements
    10Topics
    |
    11 Quizzes
  4. JavaScript: Functions
    10Topics
    |
    11 Quizzes
  5. JavaScript: Scope
    6Topics
    |
    7 Quizzes
  6. JavaScript: Arrays
    11Topics
    |
    12 Quizzes
  7. JavaScript: Loops
    8Topics
    |
    9 Quizzes
  8. JavaScript: High Order Functions
    3Topics
    |
    4 Quizzes
Lesson 2, Topic 3
In Progress

JavaScript: let Variable

Yasin Cakal 29 Oct 2021
Lesson Progress
0% Complete

The let keyword was introduced in ES6 as indicated in the previous exercise. The let keyword indicates that the variable can be reassigned a new value. Consider the following example:

let flower = 'Jasmin';
console.log(flower); // Output: Jasmin
flower = 'Rose';
console.log(flower); // Output: Rose

Another thing to keep in mind while using let (and even var) is that we can declare a variable without assigning it a value. In this example, the variable will be initialized with the undefined value :

let token;
console.log(token); // Output: undefined
token = 150;
console.log(token); // Output: 150

Take note of the following in the above example:

  • If we don’t assign a value to a variable declared using the let keyword, it defaults to undefined.
  • We can reassign the variable’s value anytime.

Responses

Leave a Reply

%d bloggers like this: