Top 50+ Node.js Live Technical Interview Questions and Answers for 2022

Node.js Interview Questions and Answers

1.Creating a Promise

const callMe = new Promise((resolve,reject)=>{
if(true){
resolve(“Resolve”)
}else{
reject(“False”)
}
})
callMe.then((result)=>{
console.log(“success”,result);
}).catch((err)=>{
console.log(“error”,error);
})

2.JavaScript Callbacks

A callback is a function passed as an argument to another function

This technique allows a function to call another function

A callback function can run after another function has finished

function myFirst() {
myDisplayer(“Hello”);
}

function mySecond() {
myDisplayer(“Goodbye”);
}

myFirst();
mySecond();

 

3.diffrence between callback and promises and asynce and await

all the 3 are same except syntax difference

promises have resolve ,reject states

async function always returns a promises

await will take the promises and converts to actual result

 

4.based on id add  two array elements to single array element example

var student = [{id:1,name:”naresh”,age:23},{id:2,name:”ramesh”,age:25}]
var marks = [{id:1,name:”naresh”,marks:360},{id:2,marks:380}]

const merge = (student,marks)=>{
const temp = []
student.forEach(x=>{
marks.forEach(y=>{
if(x.id===y.id){
temp.push({…x,…y})
}
})
})
return temp
}
console.log(merge(student,marks))

5.Based on id update array element values

var student = [{id:1,name:”naresh”,age:23},{id:2,name:”ramesh”,age:25}]
var update = [{id:1,age:95},{id:2,age:84}]

update.forEach(x=>{
student.forEach(y=>{
if(x.id===y.id){
y.age=x.age;
return false
}
})
})
console.log(student)

 

 

Related Posts

Leave a Reply

Your email address will not be published.