Javascript Questions
Warm up for Javascript interview with most asked questions and answers for junior, mid, and senior roles.
Explain WeakSet in javascript.
Show AnswerHide 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.
What are Closures?
Show AnswerHide Answer
A 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.
Explain call(), apply() and, bind() methods.
Show AnswerHide 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.
What is typeof operator?
Show AnswerHide Answer
Typeof operator is used to check the type of a variable.
Explain the difference between function declaration and function expression?
Show AnswerHide 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
What are generator functions?
Show AnswerHide Answer
Generator functions are functions that can be paused and resumed at any point. They are used to create iterators.
What is an Immediately Invoked Function in JavaScript?
Show AnswerHide Answer
An Immediately Invoked Function is a function that is automatically invoked when it is defined.
Explain WeakMap in javascript.
Show AnswerHide 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.
What is the use of a Map object in JavaScript?
Show AnswerHide Answer
Map object is used to perform map operations.
What is the purpose of setTimeout and setInterval function?
Show AnswerHide Answer
setTimeout and setInterval functions are used to perform asynchronous operations.