

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Variable defined with a reserved word const can be changed - JavaScript?
You cannot change the value of an object when it is defined using const keyword.
After changing it will remain same.
Let’s say the following is our variable defined with const −
const details1 = { firstName: 'David', subjectDetails: { subjectName: 'JavaScript' } }
Example
Following is the code to change the const variable, which would only display the initial value −
const details1 = { firstName: 'David', subjectDetails: { subjectName: 'JavaScript' } } const details2 = { ...details1, subjectDetails: { ...details1.subjectDetails }, firstName: 'David' } details2.subjectDetails.subjectName = 'Java ' console.log(details1);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo225.js.
Output
The output is as follows −
PS C:\Users\Amit\JavaScript-code> node demo225.js { firstName: 'David', subjectDetails: { subjectName: 'JavaScript' } }
- Related Questions & Answers
- Can a C++ variable be both const and volatile?
- How can I check whether a variable is defined in JavaScript?
- Why is 'class' a reserved word in JavaScript?
- Is name a reserved word in MySQL?
- Select into a user-defined variable with MySQL
- How to check a not-defined variable in JavaScript?
- How can we store a value in user-defined variable?
- Can we use reserved word ‘index’ as MySQL column name?
- JavaScript Const
- MySQL ORDER BY with numeric user-defined variable?
- How to modify a const variable in C?
- How Can we permanently define user-defined variable for a client in MySQL?
- How to initialize const member variable in a C++ class?
- Program to find out the total number of characters to be changed to fix a misspelled word in Python
- In MySQL, why a client cannot use a user-defined variable defined by another client?
Advertisements