Advance JavaScript Interview Questions

What will be output:

const object = {
  message: 'Hello, World!',

  getMessage() {
    const message = 'Hello, Earth!';
    return this.message;



'Hello, World!'

What will be the output of the code below and why?

var a="Hello";
let b=10;

The first console will give undefined and another one will give Reference Error: Cannot access ‘b’ before initialisation. The reason behind this is how JavaScript executes the code. There are two phases of execution:creation phase and execution phase. In creation phase JavaScript allocates memory to its variables and functions and for variables declared with var, JavaScript initialises them with undefined and that’s why when we log “a” before its initialisation, its value is undefined. In case of let and const declared variables, they are initialised at a different memory location and are not accessible to us before their initialisation, this is called “temporal dead zone”. And that’s why JavaScript gives us a reference error in this case.

How we can add or remove properties to objects?

 let user = new Object();

    // add a property’John’;

    user.age  =21;


    delete user.age;


What would be the result of 3+2+”7″?

Since 3 and 2 are integers, they will be added numerically. And since 7 is a string, its concatenation will be done. So the result would be 57.

What is the difference between primitive types and structural types in JavaScript?

What is the difference between undefined and null ?

What is prototypal inheritance?

What is prototypal inheritance?

Can you explain the idea of immutability on a high level?

What is a reference type?

Can you explain polymorphism on a high level?

Can you explain the difference between using map and forEach ?

When should you declare functions in the global scope?

What happens when a function is created in terms of the call stack?

Explain one way to dynamically select DOM nodes using JavaScript.

- Can you please write promise which retrun true on resolve and false on rejected

- Samw with async await

 How can the style/class of an element be changed?

document. getElementById ("myText"). className = "anyclass";