Languages
[Edit]
EN

JavaScript - constants

0 points
Created by:
user4838
698

In this article, we would like to show you how to declare and use constants using the const keyword in JavaScript.

Syntax

Edit

Description

Edit

Constants are declared using the const keyword and they must be initialized. They are block-scoped such as variables declared using the let keyword. The constant values can't be changed through reassignment, and they can't be redeclared. However, if you create a constant object or array its properties or items can be updated or removed.

Practical examples

Edit

Example 1

Edit

In this example, we create a constant and try to reassign a value to it.

Output:

Example 2

Edit

In this example, we create an uninitialized constant.

Output:

Example 3

Edit

This example shows, that constants are block-scoped.

Output:

References

Edit
  1. const - JavaScript | MDN

Alternative titles

  1. JavaScript - const keyword
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

JavaScript - Statements & declarations

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join