Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
const | Variables and Data Types
Introduction to JavaScript

constconst

Another way to define a variable in JavaScript is using the const keyword. The primary difference between let and const is that variables created using const cannot change their values, whereas using the let keyword allows changes to the variable's value.

Let's compare the behavior of variables using let and const. Take a look at the following example where we can change the value of the a variable:

In contrast, let's examine the behavior of the b variable. We will encounter an error: TypeError: Assignment to a constant variable.

Usage

Constants are used as immutable variables. You can define a constant once and use it multiple times.

Constants provide data integrity while allowing for quick refactoring.

Note

Refactoring involves making structural changes to the code, such as modifying values, variable/function names, and more.

For example, consider maxHeight for site elements. You can release a site update by changing the maximum height of elements with just one modification in the code. However, it's important to note that you cannot change the maximum height during runtime, ensuring data integrity.

question-icon

Define a constant variable:

= 50;

Натисніть або перетягніть елементи та заповніть пропуски

Все було зрозуміло?

Секція 2. Розділ 3
course content

Зміст курсу

Introduction to JavaScript

constconst

Another way to define a variable in JavaScript is using the const keyword. The primary difference between let and const is that variables created using const cannot change their values, whereas using the let keyword allows changes to the variable's value.

Let's compare the behavior of variables using let and const. Take a look at the following example where we can change the value of the a variable:

In contrast, let's examine the behavior of the b variable. We will encounter an error: TypeError: Assignment to a constant variable.

Usage

Constants are used as immutable variables. You can define a constant once and use it multiple times.

Constants provide data integrity while allowing for quick refactoring.

Note

Refactoring involves making structural changes to the code, such as modifying values, variable/function names, and more.

For example, consider maxHeight for site elements. You can release a site update by changing the maximum height of elements with just one modification in the code. However, it's important to note that you cannot change the maximum height during runtime, ensuring data integrity.

question-icon

Define a constant variable:

= 50;

Натисніть або перетягніть елементи та заповніть пропуски

Все було зрозуміло?

Секція 2. Розділ 3
some-alt