Frequently used JavaScript Interviews Questions and Answer

Debashis Ray
3 min readMay 8, 2021
  1. What are truthy and falsy values?

Answer: In boolean context, a conditional variable value that returns true is called truthy value. All values are truthy values unless it declared as falsy values. Falsy values are 0, empty string, undefined, null, NaN, false.

2. Difference Between Undefined and Null?

Answer: Undefined means not defined. It is a type. It means declaring a variable but no value assigned. When I access a property of an object but this property is not declared then I get undefined. On other hand, Null means not exist. It is an object. I can assign it to a variable.

3. What is double equal (==) and triple equal (===)?

Answer: Double equal (==) is the comparison operator. It transforms the operand into the same type before comparison. Triple equal (===) is a strict equality comparison operator. It checks operand type before comparison. For example: If we compare “2” with 2 using double equal (==) then it returns true and triple equal (===) then it returns false.

4. What is scope and block scope?

Answer: Scope determines the accessibility of variables. There are two types of scope: 1. Global scope, 2. Local scope

Global scope: The area outside the functions is called global scope. Declared variable in global scope is accessed and altered in any other scope.

Local scope: The area inside the functions is called local scope. Declared variable in the local scope is not accessed outside the function. Local scope are two types 1. function scope, 2. block scope

Function Scope: When declaring a function it created a function scope. When a variable is declared in function scope, it would not access outside the function. Var is the keyword to declare a variable in the function scope.

Block Scope: The area within if, switch conditions or for and while loops are called block scope. The const and let are the keywords to declare a variable in the block scope.

5. What is Closure?

Answer: When a function calls or returns a function then it creates a closed environment is called closure. A closure gives access to the outer function scope from the inner function.

6. Difference between call and apply?

Answer: If I want to use one object method in another object then I can use call, apply or bind. The ‘call’ and ‘apply’ are similar almost. They invoke a function with this context and optional arguments. Call take arguments one by one with comma separation. And apply take arguments as an array.

7. What the heck of the ‘this’ keyword?

Answer: At the time of function execution, JavaScript Engine set a property for the function called ‘this’. ‘this’ is referred current execution context. ‘this’ keyword always refers to an object and how a function is called. While a function executing inside the context is an object, the object becomes the value of this.

8. What is setTimeout()?

Answer: setTimeout() is a native JavaScript function. The setTimeout() method calls a function or evaluates an expression after a specified number of milliseconds. setTimeout() allows us to run a function once after the interval of time.

9. What is setInterval()?

Answer: setInterval() is a JavaScript method. The setInterval() method calls a function or evaluates an expression after specified intervals. The setInterval() method offered on the Window and Worker interfaces, repeatedly calls a function or executes a code snippet, with a fixed delay between each call. It returns a unique interval ID that identifies the interval.

10. What are arrow functions?

Answer: Arrow functions were introduced in the ES6 of JavaScript. They provide us with a new and shorter syntax for declaring functions. Arrow functions can only be used as a function expression.

--

--