Author: Not specified | Language: javascript |
Description: Not specified | Timestamp: 2018-04-17 10:25:32 +0000 |
View raw paste | Reply |
- // Using a string method doesn't mutate the string
- var bar = "baz";
- console.log(bar); // baz
- bar.toUpperCase()
- console.log(bar); // baz
- // Using an array method mutates the array
- var foo = [];
- console.log(foo); // []
- foo.push("plugh");
- console.log(foo); // ["plugh"]
- // Assignment gives the primitive a new (not a mutated) value
- bar = bar.toUpperCase(); // BAZ
View raw paste | Reply |