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

Comments: 2

profile
@niteshguptav63
17-Nov-2024, 01:39 PM

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

profile
@niteshguptav63
16-Nov-2024, 10:56 AM

When will I get my course?

profile
@admin79
17-Nov-2024, 01:29 PM

Now, Your query was resolved.

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?