ES2015 (ES6) Notes

Strict
‘use strict’
 
Const, Let
const —> value stays constant not reassigned, does not work for array or objects
let —> value reassigns, use let instead of var when using if loops, only block level scoping
var —> avoid usage

 

String Search
Arrow function syntax
function sayHi = () => console.log(“Hi ” + name);
const square = x => x * x;
const multiply = (x, y) => x * y

 

Default Parameters

set default values for function with parameters

 

Rest Operator
Represent indefinite number of arguments as an array.
e.g. …params
Spread Operator
Allow expression to be expanded for multiple arguments, elements or variables.
e.g. …args
Destructuring
Extract data from arrays or objects into distinct variables.
Object Property
For..Of
for (let cat of cats) {…}
Set
Collection of values, not an array but behave like one
mySet.add(1);
mySet.has(1);
mySet.delete(1);
Array.from(): array from set
new Set(arrayOfX): set to array
Map
Simple key/value map
e.g.
let stevenJ = { name: ‘Steven’, age: 22 },
    sarah = { name: ‘Sarah’, age: 23 },
    stevenS = { name: ‘Steven’, age: 22 };
mySet.clear: remove all key/value pairs
mySet.delete: removes value of key
mySet.get: return value of key
mySet.has: whether value has key or not
mySet.set: sets value for key

 

Class
special functions, class expressions & class declarations
define at top of file
class Animal { … }
Class Documentation – Mozilla Developer Network

 

Static Methods
static function(x, y) {…};

 

Getter, Setter
get name() {
     return `${this.firstName} ${this.lastName}`;
}
set name(input) {
     let name = input.split(‘ ‘);
     this.firstName = name[0];
     this.lastName = name[1];
}
console.log(person.name);
this.firstName = firstName
this.lastName = lastName

Leave a Reply

Your email address will not be published. Required fields are marked *