Section 2
by Louis Nguyen· Module 3

Root Folder
Not Attempted
NameProgress
JavaScript for Beginners Introduction
Not Read
Setting up environment
Not Read
Module 1: Engaging with JavaScript Fundamentals
Not Attempted
NameProgress
Section 1
Not Read
Section 2
Not Read
Section 3
Not Read
Module 1 Quiz
Not Attempted
Module 2: Introduction to Variables and Data Types
Not Attempted
NameProgress
Section 1
Not Read
Arithmetic Operations
Not Read
Type Conversion
Not Read
Section 1
Not Attempted
Section 2
Not Attempted
0 / 400 XP

In this lesson, we'll explore the concept of Constants in JavaScript. Constants are a type of variable whose value cannot be changed once it has been set. 

What is a Constant?
A constant is a variable declared with the const keyword. The value of a constant cannot be reassigned after its initial assignment. Constants are often used to store values that should remain constant throughout the execution of a program, such as fixed values like mathematical constants or configuration settings.

Example:

const PI = 3.14159;

In this example, PI is a constant that holds the value of the mathematical constant (pi). If you let PI = 4 then it will give an error

Characteristics of Constants

  1. Immutable: Once a constant is assigned a value, it cannot be changed.
  2. Block-scoped: Constants have block scope, similar to variables declared with let.
  3. Must be initialized: A constant must be initialized at the time of declaration.

Let's use constants in a practical example. We'll create an HTML page where users can enter the radius of a circle, and JavaScript will calculate and display the circumference.

Discussion

0 comments
Loading editor ...
Remember to be polite and report any undesirable behaviour

Category

Empty

Labels

Discussion has no labels

1 participant

user avatar

Priority

Notifications

You're not receiving notifications from this thread.
Loading...
Ready ...
Course Outline
Module 1: Engaging with JavaScript Fundamentals
Module 2: Introduction to Variables and Data Types
Module 3
Module 4
Module 5