Professional Documents
Culture Documents
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 constructor function ,
scoping and hoisting undeclared We cannot manipulate the value of this prototype property is created for that
problem in ES5 is variable with keyword inside the arrow function when we constructor function
solved in ES6.Variables var keyword in use call,apply or bind The only inconvenience of using prototypes
declared with the var ES5 we get We do not have access to the prototype is that there is no easy way to create private
keyword can not have undefined field when we declare the function using fat methods or variables.
Block Scope. Variables variable name arrow symbol Ref -- https://stackoverflow.com/questions/‐
declared inside a block {} error. This is
8433459/what-s-the-purpose-of-prototype
can be accessed from the example for Default function parameters
Ref -- https://idiallo.com/javascript/why-u‐
outside the block. hositing
when we set up default function parameters se-prototypes
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=(price,cost=0.07)=>{ //for of loop is used in
It defines a constant keyword ,
console.log(price*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 console.log(i);
can change the Error as Refe‐ Rest Spread }
properties of constant rence Error It allows to convert the no It allows to
objects. <variable 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 console.log(a)//12
This keyword
function definition or denoted by var f = 0b111;
The JavaScript this keyword refers to the function expression the "..." , but console.log(f);
object it belongs to. It has different values used to
depending on where it is used: In a method, destructure Template literals
this refers to the owner object. Alone, this the array
refers to the global object It can create the multiline strings
a = (...data)=>{ Spread
The 4 rules of finding out the value of console.log(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 constructor 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 instantiated 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 constructor 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://javascript.info/rest-paramet‐ Ref -- https://developer.mozilla.org/en-US/‐
set the value of this explicitly.
ers-spread-operator docs/Web/JavaScript/Reference/Operat‐
Rule 4 : Whenever we create a object using ors/new.target
new keyword inside the function definition,
Object Literal
the this keyword refers to the new object Example
that is being created It is shorthand for initializing the object
properties and also method
class A{
Ref -- https://dev.to/sarah_chima/enhanc‐
constructor(){
ed-object-literals-in-es6-a9d
this.data = 55;
console.log("Inside the base")
console.log(new.target.dumm())
}
}
class B extends A{
constructor(){
super()
console.log(new.target)
console.log(typeof B)
this.data = 66;
console.log(this.data)
}
static dumm(){
return 57;
}
}