ES6 Flashcards
(31 cards)
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.
What is Hoisting
Its a JS mechanism where variables and functions declaration are moved at top of their scope before executing.
a=1; log(a+1); //2 var a ------------------------- log(a+1); // Undefined a=1; var a; For let it will throw error while assigning only.
Types of scope
- Block Scope
- Function Scope
- Module Scope
- Global Scope
- Lexical Scope
What is Scope
Policy that Manages Accessibility of variable.
Lexical Scope
Accessing a variable inside inner function while it is declared in outer function.
What is Closure
Creating Function inside another Function.
Inner Function
Call, Apply and Bind
Call fun Invokes function passing object in first argument and Then other args seperating by comma.
Example : invite.call( obj, ‘hi’, 123 )
Apply fun Invokes function passing object in first argument and Then other args are sent in array.
Example : invite.call( obj, [‘hi’, “hello”] )
Bind will return new functions and it allows to pass argument. var inviteemployee = invite.bind(emp) inviteemployee( 'hi' , 'hello' );
Scope Chain
While executing a function, to use a variable it will check for the value of variable inside scope if not found it search outer scope if still not found search in global scope this is called scope chain.
IIFE
immediate invoked Function Expression
(IIFE) is js function that runs as soon as it is defined.
- Primary reason to use this function is to obtain data privacy.
- Variables cannot be accessed in iife.
Immutable objects
Add Delete Change
Object.Freeze() X X X
Object.seal() X X yes
Object. Prevent-extension() X yes yes