You are on page 1of 2

ES6 Cheat Sheet

by arrow96 via cheatography.com/77976/cs/19118/

Let and Const Arrow Functions Prototype

let and const Hoisting Arrow function or fat arrow function -- All JavaScript objects inherit properties and
problem shorter version of syntax when compared to methods from a prototype.
let -- allows block When we use a the normal function When we create the constr​uctor function ,
scoping and hoisting undeclared We cannot manipulate the value of this prot​otype property is created for that
problem in ES5 is variable with keyword inside the arrow function when we constr​uctor function
solved in ES6.Va​riables var keyword in use call​,apply or bind The only inconv​enience of using prototypes
declared with the var ES5 we get We do not have access to the prot​otype is that there is no easy way to create private
keyword can not have unde​fined field when we declare the function using fat methods or variables.
Block Scope. Variables variable name arrow symbol Ref -- https:​//s​tac​kov​erf​low.co​m/q​ues​tio​ns/​‐
declared inside a block {} error. This is
843​345​9/w​hat​-s-​the​-pu​rpo​se-​of-​pro​totype
can be accessed from the example for Default function parameters
Ref -- https:​//i​dia​llo.co​m/j​ava​scr​ipt​/wh​y-u​‐
outside the block. hositing
when we set up default function parameters se-​pro​totypes
problem.
we get access to the functions and the
const -- It does NOT Whereas when
variables in the context for of loop
define a constant value. we use let
data=​(pr​ice​,co​st=​0.0​7)=​>{ //for of loop is used in
It defines a constant keyword ,
consol​e.l​og(​pri​ce*​cost) }
reference to a value. hoisting iterable
data(5.00)
Because of this, we problem is var a = [1,2,2​,2,2];
cannot change constant solved in ES6. for ( let i of a) {
primitive values, but we We get the Rest and spread operator consol​e.l​og(i);
can change the Error as Refe​‐ Rest Spread }
properties of constant rence Error It allows to convert the no It allows to
objects. <va​riable of parameters into an array convert the Octal and binary Literals
name> not array into an var a = 0O12; //octal literals
defined. parameters either O or o is allowed
It is denoted by "..."​ in the It is also consol​e.l​og(​a)//12
This keyword
function definition or denoted by var f = 0b111;
The JavaScript this keyword refers to the function expression the "..."​ , but consol​e.l​og(f);
object it belongs to. It has different values used to
depending on where it is used: In a method, destru​cture Template literals
this refers to the owner object. Alone, this the array
refers to the global object It can create the multiline strings
a = (...da​ta)​=>{ Spread
The 4 rules of finding out the value of consol​e.l​og(​data) } operator can
new.target
this keyword a(2,3,​3,3​,3)​(​5) [2, split the
The new.target property lets you detect
Rule 1 : When the keyword this is not 3, 3, 3, 3]a(​2,3​,3,​‐ string into
whether a function or constr​uctor was
inside the declared object then it refers to 3,3​,)(​5) [2, 3, 3, char
called using the new operator. In constr​‐
the global object 3, 3]
uctors and functions instan​tiated with the
Rule 2 : When the keyword this is inside The rest parameters must a = new operator, new.target returns a
the declared object , then it refers to the be at the end [...'acd'] reference to the constr​uctor or function. In
closest parent object
(3) ["a​", normal function calls, new.target is
Rule 3 : whenever the context of the object "​c", "​d"] undefined.
changes , we use call , apply and bind to
Ref -- https:​//j​ava​scr​ipt.in​fo/​res​t-p​ara​met​‐ Ref -- https:​//d​eve​lop​er.m​oz​ill​a.o​rg/​en-​US/​‐
set the value of this explic​itly.
ers​-sp​rea​d-o​perator doc​s/W​eb/​Jav​aSc​rip​t/R​efe​ren​ce/​Ope​rat​‐
Rule 4 : Whenever we create a object using ors​/ne​w.t​arget
new keyword inside the function defini​tion,
Object Literal
the this keyword refers to the new object Example
that is being created It is shorthand for initia​lizing the object
properties and also method
class A{
Ref -- https:​//d​ev.t​o/​sar​ah_​chi​ma/​enh​anc​‐
constr​uct​or(){
ed-​obj​ect​-li​ter​als​-in​-es​6-a9d
this.data = 55;
consol​e.l​og(​"​Inside the base")
consol​e.l​og(​new.ta​rge​t.d​umm())
}
}

class B extends A{
constr​uct​or(){
super()
consol​e.l​og(​new.ta​rget)
consol​e.l​og(​typeof B)
this.data = 66;
consol​e.l​og(​thi​s.data)
}
static dumm(){
return 57;
}
}

By arrow96 Not published yet. Sponsored by Readable.com


cheatography.com/arrow96/ Last updated 20th March, 2019. Measure your website readability!
Page 1 of 2. https://readable.com

You might also like