Now! But it depends where. Node.js supports most/nearly all new things. [Chrome, Firefox, Edge, and Safari have been keeping up well](http://caniuse.com/#search=es6). But new features are being added and tested. To be sure that code will run across many platforms (never forget the people who still use IE8), many people have come to rely on transpilers/compilers. Transpilers/Compilers take 'dialects' of standard code (incuding ES6, coffeescript, typescript and more) and convert the code for you. A popular one for ES6 is [Babel](https://babeljs.io/), they have both repl (Read, Evaluate, Print, Loop) and an npm module/gem.
Node.js supports most/nearly all new things. [Chrome, Firefox, Edge, and Safari have been keeping up well](http://caniuse.com/#search=es6). But new features are being added and tested. To be sure that code will run across many platforms (never forget the people who still use IE8), many people have come to rely on transpilers/compilers. Transpilers/Compilers take 'dialects' of standard code (incuding ES6, coffeescript, typescript and more) and convert the code for you. A popular one for ES6 is [Babel](https://babeljs.io/), they have both repl (Read, Evaluate, Print, Loop) and an npm module/gem.


@ -188,14 +191,14 @@ for(var i=0; i<5; i++){
A new way to get block level scoping is with the keyword let, and the use of `{}` as in any `{}`, not just tied to a function! Note: `let` is NOT meant to completely replace `var`!
A new way to get block level scoping is with the keyword let, and the use of `{}` as in any `{}`, not just tied to a function! Note: `let` is NOT meant to completely replace `var`!
```JavaScript
```JavaScript
var a = 2
let a = 2
{
{
let a = 4
let a = 4
console.log( 'the value of b inside the `{}` is', a); //"block level scope"
console.log( 'the value of a inside the `{}` is', a); //"block level scope"
}
}
console.log ('the value of b outside of the `{}` is', a) //"global scope"
console.log ('the value of a outside of the `{}` is', a) //"global scope"
```
```
And now the loop with setTimeout:
And now the loop with setTimeout:
@ -317,20 +320,23 @@ me.logName();
```JavaScript
```JavaScript
class Cat {
class Cat {
static getTypes(){
return ['large', 'small'];
}
constructor(name) {
constructor(name) {
this.name = name;
this.name = name;
}
}
makesNoises() {
makesNoises() {
return (this.name + 'meows');
return this.name + 'meows';
}
}
purrs(){
purrs(){
return (this.name + 'purrs');
return this.name + 'purrs';
}
}
}
}
class Lion extends Cat {
class Lion extends Cat {
makesNoises() {
makesNoises() {
return (this.name + 'roars!');
return this.name + 'roars!';
}
}
eatHuman(){
eatHuman(){
return 'yum';
return 'yum';
@ -345,6 +351,31 @@ var myLion = new Lion("Simba");
console.log(myLion.makesNoises());
console.log(myLion.makesNoises());
console.log(myLion.purrs());
console.log(myLion.purrs());
console.log(myLion.eatHuman());
console.log(myLion.eatHuman());
console.log(Cat.getTypes());
```
This makes inheritance much easier than how it used to be:
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: