immutable values

Solutions on MaxInterview for immutable values by the best coders in the world

showing results for - "immutable values"
Maelyss
10 Feb 2018
1let a = {
2    foo: 'bar'
3};
4
5let b = a;
6
7a.foo = 'test';
8
9console.log(b.foo); // test
10console.log(a === b) // true
11let a = 'test';
12let b = a;
13a = a.substring(2);
14
15console.log(a) //st
16console.log(b) //test
17console.log(a === b) //false
18let a = ['foo', 'bar'];
19let b = a;
20
21a.push('baz')
22
23console.log(b); // ['foo', 'bar', 'baz']
24
25console.log(a === b) // true
26let a = 1;
27let b = a;
28a++;
29
30console.log(a) //2
31console.log(b) //1
32console.log(a === b) //false