Const

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 169:- Const

In JavaScript, const is a keyword that is used to declare a variable whose value cannot be reassigned. Once a variable is declared with const, its value remains constant throughout the program. If you try to reassign the value of a const variable, you will get a TypeError.

For example, consider the following code:

arduinoCopy code

const x = 10; x = 20; // TypeError: Assignment to constant variable.

Here, the value of x is declared as 10 using const. When we try to reassign x to 20, we get a TypeError since x is a const variable and its value cannot be changed.

It is important to note that while const prevents reassignment of the variable itself, it does not prevent mutation of the object or array that the variable is referring to. For example:

arduinoCopy code

const arr = [1, 2, 3]; arr.push(4); // OK const obj = { foo: "bar" }; obj.baz = "qux"; // OK

Here, we declared a const variable arr as an array, and we added a new element to the array using push(). Similarly, we declared a const variable obj as an object and added a new property to the object using dot notation.

20. Mini Project Using JavaScript

2 Comments

@niteshguptav63
niteshguptav63 Nov 17, 2024 at 1:39 PM

I am not able to access videos from second class and further. I have already completed first class

@niteshguptav63
niteshguptav63 Nov 16, 2024 at 10:56 AM

When will I get my course?

@admin79
admin79 Nov 17, 2024 at 1:29 PM

Now, Your query was resolved.

Frequently Asked Questions About Sciaku Courses & Services

Quick answers to common questions about our courses, quizzes, and learning platform

Didn't find what you're looking for?

help_center Contact Support