Javascript Interview Questions

What is Difference between == and === operator in JavaScript

Answer: The difference between ==(abstract equality) and ===(strict equality) is that the == compares by value after coercion and === compares by value and type without coercion.



In general “===” operator is recommended since it never does type conversion we are doing an exact comparison thus it always produces correct results.

Rules of implicit coercion :

  • If one operand is a string and another is a number, the string will be converted to a number.
  • if one operand is Boolean and the others are non-boolean, Boolean will converted to number.
  • While comparing a string or number with an object, the object will be converted to a primitive type.

Null vs Undefined:

Undefined means a variable has been declared but has not yet been assigned a value.

null is an assignment value. It can be assigned to a variable as a representation of no value.

Different ways to get undefined

  1. Uninitialized variable: variable without assigning a value is undefined.
  2. accessing a non-existing property.
  3. 3. The function parameter implicitly default to undefined.

4. Javascript function returns undefined without a return statement.


Scope in javascript refers to the current context of the code, which determines the accessibility of the variable to JavaScript. There are two types of scope.

  1. global: outside of a block.
  2. local: inside of a block.

Block Scope:

The area between {curly brackets} is known as a scope.


The closure is created every time when a function is created. Closure gives you access to an outer function's scope from an inner function.


The setTimeOut function calls a function or evaluates an expression after a specified number of milliseconds


setInterval executes function continuously after a certain millisecond of time.

Difference between bind, call, apply:

if we want to use one method to another object then we need to use bind, call and apply

in a bind, we need to pass the object name as an argument,

in a call, we need to pass the object name and all argument by comma separation

in apply we need to pass the object name as a first argument and 2nd argument is an array of method arguments

Explain Event Bubbling?

Answer: When an event is triggered from an element, the event handler/event listener tied to that event is called. When an event is fired on an element that has parent elements, it runs through a “bubbling” phase. During the “bubbling” phase, the browser checks to see if the element that triggered the event has an event handler registered to it. If it does, it runs the event handler. If it does not, it moves to the parent element and checks if it has an event handler registered to it. The browser continues to move up the chain of parent elements, checking for and executing registered event handlers, until it reaches the root element.

What’s the value of this in JavaScript?

Answer: Basically, this refers to the value of the object that is currently executing or invoking the function. I say currently due to the reason that the value of this changes depending on the context on which we use it and where we use it.

What is an IIFE, what is the use of it?

Answer: An IIFE or Immediately Invoked Function Expression is a function that is gonna get invoked or executed after its creation or declaration.

What is the usage of Function.prototype.bind?

Answer: The bind method returns a new function that is bound
to a specific this value or the "owner" object, So we can use it later in our code. The call,apply methods invokes the function immediately instead of returning a new function like the bind method.

What’s the difference between Function.prototype.apply and ?

Answer : The only difference between apply and call is how we pass the arguments in the function being called. In apply we pass the arguments as an array and in call we pass the arguments directly in the argument list by comma separating.

Explain Functional Programming ?

Answer: Functional Programming is a declarative programming paradigm or pattern on how we build our applications with functions using expressions that calculates a value without mutating or changing the arguments that are passed to it.

What is the Callback function?

Answer : A callback function is a function that is passed as an argument to another function, to be “called back” at a later time.