JavaScript Interview Questions and Answers

1) What are the built-in iterables?

Below are the list of built-in iterables in javascript,

  1. Arrays and TypedArrays
  2. Strings: Iterate over each character or Unicode code-points
  3. Maps: iterate over its key-value pairs
  4. Sets: iterates over their elements
  5. arguments: An array-like special variable in functions
  6. DOM collection such as NodeList

2) What are the differences between spread operator and rest parameter?

Rest parameter collects all remaining elements into an array. Whereas Spread operator allows iterables( arrays / objects / strings ) to be expanded into single arguments/elements. i.e, Rest parameter is opposite to the spread operator.

3) What are the differences between arguments object and rest parameter?

There are three main differences between arguments object and rest parameters

  1. The arguments object is an array-like but not an array. Whereas the rest parameters are array instances.
  2. The arguments object does not support methods such as sort, map, forEach, or pop. Whereas these methods can be used in rest parameters.
  3. The rest parameters are only the ones that haven’t been given a separate name, while the arguments object contains all arguments passed to the function

4) What is a prototype chain?

Prototype chaining is used to build new types of objects based on existing ones. It is similar to inheritance in a class based language. The prototype on object instance is available through Object.getPrototypeOf(object) or proto property whereas prototype on constructors function is available through object.prototype.


5) What are lambda or arrow functions?

An arrow function is a shorter syntax for a function expression and does not have its own this, arguments, super, or These functions are best suited for non-method functions, and they cannot be used as constructors.

6) What is the reason to choose the name let as a keyword?

Let is a mathematical statement that was adopted by early programming languages like Scheme and Basic. It has been borrowed from dozens of other languages that use let already as a traditional keyword as close to var as possible.

7) What is the benefit of using modules?

There are a lot of benefits to using modules in favour of a sprawling. Some of the benefits are,

  1. Maintainability
  2. Reusability
  3. Namespacing

8) What are modules?

Modules refer to small units of independent, reusable code and also act as the foundation of many JavaScript design patterns. Most of the JavaScript modules export an object literal, a function, or a constructor.

9) Why do you need modules?

Below are the list of benefits using modules in javascript ecosystem

  1. Maintainability
  2. Reusability
  3. Namespacing

10) What is scope in javascript?

Scope is the accessibility of variables, functions, and objects in some particular part of your code during runtime. In other words, scope determines the visibility of variables and other resources in areas of your code.

11) How do you manipulate DOM using a service worker?

Service worker can’t access the DOM directly. But it can communicate with the pages it controls by responding to messages sent via the postMessage interface, and those pages can manipulate the DOM.

12) How do you reuse information across service worker restarts?

The problem with service worker is that it gets terminated when not in use, and restarted when it’s next needed, so you cannot rely on global state within a service worker’s onfetch and onmessage handlers. In this case, service workers will have access to IndexedDB API in order to persist and reuse across restarts.

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

Recommended Posts:

Editorial Staff

Editorial Staff at FreeWebMentor is a team of professional developers.

Comments and Discussions

Your email address will not be published. Required fields are marked *