Javascript Questions

Warm up for Javascript interview with most asked questions and answers for junior, mid, and senior roles.

Senior

Explain WeakSet in javascript.

Show Answer

WeakSet is a collection of objects that are stored using a weak reference. This means that the objects in the set are not directly accessible from outside the set.

Senior

What are Closures?

Show Answer

closure is a stateful function that is returned by another function.

It has access to the parent scope, even after the parent function has closed.

Senior

Explain call(), apply() and, bind() methods.

Show Answer

The call() invokes the function and allows you to pass in arguments one by one.

 

The apply() invokes the function and allows you to pass in arguments as an array.

 

The bind() method creates a new function that, when called, has this keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.

Senior

What is typeof operator?

Show Answer

Typeof operator is used to check the type of a variable.

Senior

Explain the difference between function declaration and function expression?

Show Answer

Function declarations

  • like vars, they will be automatically hoisted
  • load before any other code

 

Function expressions

  • not hoisted
  • only loads when the interpreter reaches it
Senior

What are generator functions?

Show Answer

Generator functions are functions that can be paused and resumed at any point. They are used to create iterators.

Senior

What is an Immediately Invoked Function in JavaScript?

Show Answer

An Immediately Invoked Function is a function that is automatically invoked when it is defined.

Senior

Explain WeakMap in javascript.

Show Answer

WeakMap is a collection of key-value pairs where the keys are stored using a weak reference. This means that the keys are not directly accessible from outside the map.

Senior

What is the use of a Map object in JavaScript?

Show Answer

Map object is used to perform map operations.

Senior

What is the purpose of setTimeout and setInterval function?

Show Answer

setTimeout and setInterval functions are used to perform asynchronous operations.