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