
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
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 Articles
- 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?
- Can we use reserved word ‘index’ as MySQL column name?
- 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?
- MySQL ORDER BY with numeric user-defined variable?
- How to modify a const variable in C?
- JavaScript Const
- How Can we permanently define user-defined variable for a client in MySQL?
- How to initialize const member variable in a C++ class?
- How can I check if a JavaScript function is defined?
- In MySQL, why a client cannot use a user-defined variable defined by another client?

Advertisements