ES2015 (ES6) Notes

‘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
Extract data from arrays or objects into distinct variables.
Object Property
for (let cat of cats) {…}
Collection of values, not an array but behave like one
Array.from(): array from set
new Set(arrayOfX): set to array
Simple key/value map
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


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];
this.firstName = firstName
this.lastName = lastName

Leave a Reply

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