You can add trailing commas to make copy/paste easier later on:
```javascript
var arr = [
1,
2,
3, //the comma here will not cause issues
];
console.log(arr);
```
If you have multiple commas, it will create holes in the array:
```javascript
var arr = [
1,
2,
3,,,,
];
console.log(arr);
console.log(arr.length); //logs 6
```
Trailing commas are okay in objects too:
```javascript
var object = {
foo: "bar",
baz: "qwerty",
age: 42,
};
console.log(object);
```
## Template Literals (String Interpolation)
Template literals allow you to insert variables into strings with out having to use `+`
@ -722,3 +789,105 @@ var y = false;
console.log(x,y);
```
## Merge objects
You can use `Object.assign()` to merge properties of two or more objects:
```javascript
var a = {
foo:'bar'
}
var b = {
awesome:true
}
Object.assign(a, b);
console.log(a);
```
This is extremely useful when you need to create a brand new object that is a clone of another one with some minor changes (happens all the time with Redux):
```javascript
var bob = {
name:'Bob',
age: 42
}
var sally = Object.assign({}, bob, {name:'Sally'})
console.log(sally);
```
## Array functions
There are a bunch of cool new array helper functions:
```javascript
var nums = [1,3,5,7,8];
var largeNums = nums.filter(function(currentNum){
return currentNum > 5
});
console.log(largeNums);
var sum = nums.reduce(function(accumulatedValue, currentNum){
return accumulatedValue + currentNum;
});
console.log(sum);
var doubledValues = nums.map(function(currentNum){
return currentNum * 2;
})
console.log(doubledValues);
var found = nums.find(function(currentNum) {
return currentNum > 5;
});
console.log(found);
var found = nums.findIndex(function(currentNum) {
return currentNum > 5;
});
console.log(found);
var doesFiveExist = nums.includes(5);
console.log(doesFiveExist);
var doubleArray = nums.concat(nums);
console.log(doubleArray);
var section = nums.slice(2,4)
console.log(section);
```
## Asynchronous programming
Asynchronous programming used to be filled with nested callbacks and promises: