Name | Progress |
---|---|
JavaScript for Beginners Introduction | Not Read |
Setting up environment | Not Read |
Name | Progress |
---|---|
Section 1 | Not Read |
Section 2 | Not Read |
Section 3 | Not Read |
Module 1 Quiz | Not Attempted |
Name | Progress |
---|---|
Section 1 | Not Read |
Arithmetic Operations | Not Read |
Type Conversion | Not Read |
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
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.