10 JavaScript Interview Questions That Every Developer Should Know.

Saiful Islam Sojib
3 min readMay 8, 2021

--

JavaScript Interview Questions

Hi! Programmers, Today I will explore 10 JavaScript Interview Questions That Every Developer Should Know. So, let’s started….

1. Null Vs Undefined

Undefined: We can get Undefined in different ways.

  1. If we declare a variable but don’t set any values, then we get undefined.
  2. If we don’t return a value in a function, then we get undefined as the return.
  3. When We call a function and don't pass the parameter that wants to access the parameter in that function, we get undefined.
  4. If we want to read a property from an object and that property doesn't have in that object, then we get undefined.
  5. If we want to read an element from an array and that element doesn’t have in that array, then we get undefined.
  6. We can also set a value to undefined.

Null: Null is an empty or non-existent value. Null must be assigned as a value.

2. Truthy and Falsy values

Falsy values:

  1. 0
  2. undefined
  3. null
  4. NaN
  5. empty string''
  6. false

Truthy values:

  1. any number except 0. number>0 & number<0
  2. any string except empty string. string.length>0
  3. array []
  4. object {}
  5. true

3. What is Closure?

In javaScript, when a function returns another function and in this function, we access a variable that is declared in the parent function, then the child function always makes a closed environment and that is Closure.

4. Scope, Block Scope

If we declare a variable globally that is a global variable. We can access a global variable everywhere in javaScript. If we declare a variable in a function, then we can only access the variable in that function and that is the scope. We can’t access a variable that is declared in a function. we can create a block scope with curly braces { } . If I declare a variable in a block scope with var, we can access the variable in the parent scope. But If we declare a variable in a block scope with let or const, we can only access the variable in that scope.

5. Hoisting

If we declare a variable and the variable declaration will be hoisted in the same scope. If globally we declare the variable it will be hoisted in the global scope or declare the variable in a function, it will be hoisted. If we declare a variable with var, the variable declaration will be hoisted and set the undefined value, and then when we assign the variable, set the value. In the hoisting, just variable declaration will be hoisted and assignment will not be hosted. Function definition also hoisted.

6. Difference between Bind, Call and Apply

If we use this in a function or a method and we can refer to what is this object with bind, call, and apply. Bind returns a new function with this reference. With Call and Apply we can call the function with this reference. In the bind, we can use function.bind(thisArg, …arg)and it will return a function. In the call, we can use function.call(thisArg, …arg)and It will be called. In the apply, we can use function.apply(thisArg, argArray)and It will be called. In the call, we should pass arguments with a comma after thisArg and In the apply, we should pass arguments in an array after thisArg.

7. What Is IIFE Function?

The full meaning of IIFE is Immediately Invoked Function Expression. If we defined a function and we want the function will call Immediately, then we can use the IIFE function. IIFE function is an anonymous function and the function will call Immediately. We can’t call the IIFE function another time.

8. Callback Function

If in a function we receive a function with parameter and call the function in that function and the function is called a callback function.

9. What is the difference between array.map() and array.forEach()?

Array. map() use for looping an array and return an array and array.forEach() looping an array but don’t returns anything and that’s the different.

10. What is the difference between array.find() and array.filter()?

Array.find() returns the first matching element but array.filter() returns an array with all matching elements and that the difference.

--

--

No responses yet