let
and const
let
let
defines a block level variable. It can help prevent confusion in going through source code.
See the Pen UA-Let-Scoping by Jon (@Middaugh) on CodePen.
const
const
is used to generate variables that do not change.
const
We have several new feature inside of strings that are very helpful.
String concatenation is much easier with the new ES6 features. Variables can be injected into strings by using the `
(grave accent) instead of single/double quotes and using the ${x}
symbols.
^ interpolation only works within the `` ticks.
See the Pen ES6 - Interpolation by Jon (@Middaugh) on CodePen.
You can also use the `
symbol for multi line strings.
See the Pen ES6 - strings by Jon (@Middaugh) on CodePen.
Arrow functions are yet another feature introduced into ES6 that other languages leverage. Arrow functions help remove some confusion of the `this` keyword. It is very helpful, but it isn't always the best fit.
.on('click', function(){
});
.on('click', () => {
});
function(y){
var x = 3;
return x * y;
}
(y) => {
var x = 3;
return x * y;
}
var rn = function(y){
return Math.random() * y;
}
rn();
//No curly braces signifies
//it is returning the calculation.
var rn = (y) => Math.random() * y;
n(4);
Arrow functions are awesome when used with Arrays.
[].filter((element) => element.isSomething == true);
[].filter((element) => {
return element.isActive && element.isInDate
});
let
and
const
instead of
var
Fork this CodePen and convert the array method callbacks into arrow functions.