mutable data meaning code example
Example 1: what is immutable
'use strict';
const a = Object.freeze([4, 5, 6]);
const b = a.concat(7, 8, 9);
const c = a.slice(0, -1);
const d = [1, 2, 3].concat(a);
const e = a.slice(1);
const f = R.sort(myCompareFunction, a);
const g = R.reverse(a);
Example 2: immutable values
let a = {
foo: 'bar'
};
let b = a;
a.foo = 'test';
console.log(b.foo);
console.log(a === b)
let a = 'test';
let b = a;
a = a.substring(2);
console.log(a)
console.log(b)
console.log(a === b)
let a = ['foo', 'bar'];
let b = a;
a.push('baz')
console.log(b);
console.log(a === b)
let a = 1;
let b = a;
a++;
console.log(a)
console.log(b)
console.log(a === b)