Skip to Content
Mastering JavaScript Functional Programming - Second Edition
book

Mastering JavaScript Functional Programming - Second Edition

by Federico Kereki
January 2020
Intermediate to advanced
470 pages
11h 13m
English
Packt Publishing
Content preview from Mastering JavaScript Functional Programming - Second Edition

Constants

If the mutations don't happen because of using some JavaScript methods, then we might want to attempt to use const definitions, but that just won't work. In JavaScript, a const definition means that the reference to the object or array cannot change (you cannot assign a different object to it) but you can still modify the properties of the object itself. We can see this in the following code:

const myObj = {d: 22, m: 9};console.log(myObj);// {d: 22, m: 9}myObj = {d: 12, m: 4};// Uncaught TypeError: Assignment to constant variable.myObj.d = 12; // but this is fine!myObj.m = 4;console.log(myObj);// {d: 12, m: 4}

You cannot modify the value of myObj by assigning it a new value, but you can modify the current value of myObj so that ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering JavaScript Functional Programming

Mastering JavaScript Functional Programming

Federico Kereki

Publisher Resources

ISBN: 9781839213069Supplemental Content