June 2018
Intermediate to advanced
278 pages
6h 10m
English
Another important principle of FP is immutability. Modifying state and data generates cyclomatic complexity and makes any computer program prone to bugs and to inefficiency in general. Indeed, all variables should, in fact, be immutable. A variable should never change its value, from the moment it is allocated to memory until the moment it is deallocated, in order to avoid changing the state of the application.
Since ES6, it is now possible to use the const keyword to define a constant or immutable variable. Here is an example of its usage:
function myJS(){ const number = 7; try { number = 9; } catch(err) {
// TypeError: invalid assignment to const 'number' console.log(err); } }
This added feature now makes it possible to prevent ...
Read now
Unlock full access