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 4
In Progress

JavaScript: const Variable

Yasin Cakal 29 Oct 2021
Lesson Progress
0% Complete

The const keyword, which stands for constant, was also introduced in ES6. The const variables, like var and let variables can hold any value. The syntax for declaring and assigning a value to a const variable is the same as for let and var.

Consider the following example:

const webName = 'CodeOfCode';
console.log(webName); // Output: CodeOfCode

A const variable, on the other hand, cannot be reassigned because it is constant. You’ll get a TypeError if you try to reassign a const variable.

Constant variables must be given a value when they are declared. You’ll get a SyntaxError if you try to declare a const variable without a value.

Consider whether you’ll need to reassign the variable later on when deciding whether to use the let or const keyword. Use let if you need to reassign the variable; otherwise, use const.

Responses

Leave a Reply

%d bloggers like this: