10 JavaScript Interview Question

imam hasan
3 min readMay 8, 2021

1. What is the difference between ‘==’ and ‘===’ is JS

Double equal (==) is a comparison operator. It transforms the operand having the same type before comparison. It means if we try to compare a number with a string, this operator transforms the string into a number. If the string is empty then it transforms into 0 and if the string is not a valid number then it converts into NaN. Then the comparison operator returns false.

On the other hand, triple equals (===) is a strict comparison operator which means it will return false for the value which is not of a similar type.

2. What is implicit type coercion in JS?

Type coercion is an automatic or implicit conversion of values from one data type to another, like convert numbers to strings.

In the above example, JavaScript coerced the 23 number to a string and add two string values.

3. What is IIFE in JS?

An IIFE (Immediately Invoked Function Expression) is a JavaScript function that runs as soon as it is defined.

Syntax:

It is also called Self Executing Anonymous Function.

4. What is the higher-order function in JS?

A higher-order function is a function that performs operations on other functions. This operation can be either taking one or functions as an argument or returns a function or can be both.

5. What is ‘this’ keyword in JS?

In JavaScript, this keyword refers to the object it belongs to. It has different values depending on where it is used. In a function, this refers to the global object. In a function in a strict mood, this is undefined. In an event, this refers to the element that receives the event. In the global execution context, this refers to the global object whether it is strict or not.

6. What is the Scope and Scope chain in JS?

Scope refers to the current context of the code which determines the accessibility of the variables. There are two types of scope. Global scope and local scope.

Within each execution, context is a special object called the scope chain which is used to resolves variables. A scope chain is essentially a stack of currently accessible scope, from the most immediate context to the global context.

7. What are Closures in JS?

The closure is a combination of a function bundled together regarding its surrounding state. In other words, it gives access to an outer function’s scope from an inner function. A closure is created whenever a function is created.

8. What is currying in JavaScript?

Currying is an advanced technique to transform a function of arguments n, to n functions of one or fewer arguments.

9. What are callbacks?

Functions that are used as an argument to another function are called callback functions.

10. What are global variables?

A JavaScript global variable is declared outside the function or declared with a window object. It can be accessed from any function.

To declare JavaScript global variables inside the function, we need to use a window object. For example: window.value=50;

--

--