Top 10 JavaScript Interview Question

1. Truthy vs Falsy

We can check the condition in if/else the statement in Programming Language. We can pass boolean (true/false)in the if condition. in JavaScript some value is being truthy or falsy. Truthy means true & falsy means false .

2. null vs undefined

null It’s a value. If there is no value in anything, we set a value of null. and when we can not set any value or When we forgot to set any value.

3. Double equal (==) vs Triple equal (===)

Double equal == just check for value equality only, it does not check type. on the other hands Triple equal === check for value and type both.

4. Scope, block scope

The scope is the accessibility of variables. Which your variable is defined. The two types of scope.

  1. Local Scope.
  2. Global Scope.

Local is declared inside a block {}. and Global is declared outside a block {}. In javaScript var is not block scope, var is function scope.

5. Closure

The closure is a feature in javaScript, where the inner function accesses the outer function’s variable.

6. Find the largest element of an array

If we went to find max value in an array, we can do it using for loops. first, we do assign a variable, here we give the variable name is max and set the first value in default. Then start the loop, and here we put every looping value in element a variable. Then we set a condition, if element > max then max = element and when loop in close, then print max variables.

7. Remove duplicate item from an array

If we went to remove the duplicate value in an array, we can do it using for loops. first, we assign a variable. for example, we can assign a variable name uniqueArray and set a default value is empty[] Then start the loop. Here we put every looping value in element a variable. And check here have any value from that array, if not stay any value, it returns -1. So we compare to if index === -1 then we push to element in uniqueArray

8. What is Recursion

Recursion is that function, That function called itself.

9. What is callback function

When we can pass a function as a parameter in the outer function. and it calls that outer function. This is a CallBack function.

10. What is DOM?

DOM is a programming API for HTML or XML documents. it defines the logical structure of the documents and the way to access to manipulate. The DOM represents a document with a logical tree. each branch of the tree ends in a node and each node contains objects.

Front-End Developer