You are on page 1of 3

1) js promises :

Promises is an object ,which represents the eventual completion or failure of the a synch operation’s.

Promises operates in one of these states:

a) pending: initial state

b) fulfilled: completion

c) rejected: failed

Importance of promises:

1) Promises help to solve problems like

a) inversion control in call back function--attaching fetched data insted of fucntion .

b) call back hell--promise chaining .

***********************************************************************************************

2) j s hoisting:

Hoisting is a mechanism in js where

All variables, functions are declared BEFORE execution of the code

Here

Variables are initialised as undefined .

Functions are stored as it is.

***********************************************************************************************

3) js anonymous function :

It’s a function without name .

So

NOTE: Anonymous functions are used in a place where functions are used as values , by assigning to some variable.

***********************************************************************************************

4) call back function

Function that is passed as argument to another function is call back function .

***********************************************************************************************
5) rest and spread operator difference :

Rest operator:

function sum(a,b,…restp){

console.log(restp);

sum(1,2,3,4,5);

 output: [3, 4, 5]

---------------------------------------------------------------------

 list of items converted to array using rest operator

 rest operator should be last parameter --mentioned if it`s in middle then it shows error

 rest operator used in called function

----------------------------------------------------------------------

spread operator :

let arr=[1,2,3,5,4]

console.log(Math.min(...arr));

output:1;

 array converted to list of items.

 Spread is used in calling function

**********************************************************************************************

CODING Question :
1) write a function to sum(a)(b)(c) :

function sum(a) {

return (b) => {

return (c) => {

return a + b + c
}

console.log(sum(1)(2)(3));

outpt-- // 6

2) How do I return the smallest value in the array?

const arr = [14, 58, 20, 77, 66, 82, 42, 67, 42, 4]
const min = arr.reduce((a, b) => Math.min(a, b))
console.log(min)

outpt-- //4

You might also like