ES6 Flashcards
Features of es6
- > Let & Const
- > Destructring
- > Templete string
- > Iterators
- > Generators
- > Promises
- > Arrow Functions
Difference Between Var & Let & Const
- Var have Global Scope.
- Let and Const have Block Scope.
- const cannot be reinitialize we can use objects to change values in const.
Templet Literals
Templet literals are string literals ( ` ` ) allowing combine expressions.
You can use multi-line strings.
Ex : let data= '<h3>hi</h3> <h2>hello</h2>' { this will throw error} new syntax : let data= `<h3>hi</h3> <h2>hello</h2>`
String Methods
- indexOf
- lastIndexOf
- search
- slice(-12);
- substring(7, 13);
- replace
- toUpperCase
- concat
- trim
- split
Spread operator
- Represented with … 3dots.
- To manipulate array and object
allows to expand where multiple argumens are expected
Ex
arr1 = [1,2,3] & arr2 = [4,5,6]
arr3 = (…arr1,…arr2)
Rest operator
- Accept all number of arguments by …n
- Here n will use as argument inside function.
what is Set()
Create a object lets us to store Unique values of any type or objects .
let Myarray = [10,20,30,10] let myset = new Set(Myarray);
log(myset)//{ 10,20,30 }
myser.add({a:100,b:200})
log(myset)//{ 10,20,30,({a:100,b:200}))
Arrow Function
- Introduces in Es6
its a Shorthand notation for creating Functions
no need to use “Function” Keyword - Arrow Function Lexical “This” feature
Promises
Promises are used to handle Asynchronous Operations.
promise.then(function (response){ // some code }
.cache(function (error){ // catch Error }
Ex : login with axios
difference b/w settimeout and settimeinterval
settimeout : will execute only once after set time.
settimeinterval : will execute again and again after set time.
minimum time for time is 4milliseconds, if u put 0sec it will still take 4milliseconds.
data types in js
- number
- string
- object
- boolean
- undefined
Js is interpreted or compiled
—- INTERPRETED —–
Interprets each line and run it in browse.
JS is Casesensitive language
what is “ This “ Keyword
It refers to object from where it was called.
Event Loop
- Event Loop is a queue of call back functions.
- when a a-sync fun is executed all callback function is pushed into queue.
Call Stack
It is a data structure for JS interpreter to keep track of all function calls.
for example : fun function is executing then fun1 is called then interpreter will store a pointer in stack and jumps to fun 1 in the fun2 fun3 is called then again interpreter will store a pointer in stack and jumps to fun 3 after completion of fun3 then it will take top most pointer from stack and moves back until stack is empty.