ES6 Flashcards

1
Q

Features of es6

A
  • > Let & Const
  • > Destructring
  • > Templete string
  • > Iterators
  • > Generators
  • > Promises
  • > Arrow Functions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Difference Between Var & Let & Const

A
  • Var have Global Scope.
  • Let and Const have Block Scope.
  • const cannot be reinitialize we can use objects to change values in const.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Templet Literals

A

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>`
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

String Methods

A
  • indexOf
  • lastIndexOf
  • search
  • slice(-12);
  • substring(7, 13);
  • replace
  • toUpperCase
  • concat
  • trim
  • split
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Spread operator

A
  • 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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Rest operator

A
  • Accept all number of arguments by …n

- Here n will use as argument inside function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what is Set()

A

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}))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Arrow Function

A
  • Introduces in Es6
    its a Shorthand notation for creating Functions
    no need to use “Function” Keyword
  • Arrow Function Lexical “This” feature
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Promises

A

Promises are used to handle Asynchronous Operations.

promise.then(function (response){ // some code }
.cache(function (error){ // catch Error }
Ex : login with axios

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

difference b/w settimeout and settimeinterval

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

data types in js

A
  • number
  • string
  • object
  • boolean
  • undefined
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Js is interpreted or compiled

A

—- INTERPRETED —–

Interprets each line and run it in browse.
JS is Casesensitive language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what is “ This “ Keyword

A

It refers to object from where it was called.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Event Loop

A
  • Event Loop is a queue of call back functions.

- when a a-sync fun is executed all callback function is pushed into queue.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Call Stack

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is Hoisting

A

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.
17
Q

Types of scope

A
  • Block Scope
  • Function Scope
  • Module Scope
  • Global Scope
  • Lexical Scope
18
Q

What is Scope

A

Policy that Manages Accessibility of variable.

19
Q

Lexical Scope

A

Accessing a variable inside inner function while it is declared in outer function.

20
Q

What is Closure

A

Creating Function inside another Function.

Inner Function

21
Q

Call, Apply and Bind

A

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' );
22
Q

Scope Chain

A

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.

23
Q

IIFE

immediate invoked Function Expression

A

(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.
24
Q

Immutable objects

A

Add Delete Change
Object.Freeze() X X X
Object.seal() X X yes
Object. Prevent-extension() X yes yes

25
Q

Reduce

A

Execute a reducer Function each value of array resulting single output.

arr = [1,2,3]
const fun1 = ( accumulator.currval ) => { acc + cval }
log(arr.reduce(fun1)) /// 6 [1+2+3]
- We can even pass a initial value.
log(arr.reduce(fun1,1)) /// 7 [1+1+2+3]
26
Q

Event Bubbling

A

Event bubbling is a type a propagation where the event first trigger the inner most element and then successive trigger parent element.

[][][][][][][][][][]
[][][][][][][]
[][][][][]

  • Click on lower event of child automatically parent event also triggered.
27
Q

First-class function

A

Functions in language is treated like variables by assigning them to variables.

28
Q

First Order Functions

A

Function does not accept function as arguments or return any function

29
Q

Higher Order Functions

A

Function accept function as arguments and return function

30
Q

Asynchronous

A

Js is single threaded programing i,e only one thing will happen at a time

Using asynchronous we can perform long network request without blocking the main thread

  • Promises
  • Call Back
  • Async / Await
31
Q

Object Functions

A

Object.assign() : Copies the values.
Object.create() : Creates a new object.
Object.values() : Returns an array containing the values that correspond to all of a given object’s own enumerable string properties.
Object.keys()
Returns an array containing the names of all of the given object’s own enumerable string properties.

Object.freeze()
Object.isFrozen()
Object.seal()
Object.isSealed()
Object.preventExtensions()
Object.isExtensible()