10 Javascript Interview Question
Tags: javascript
Published: 2021-06-13 18:56:19

1.What are Truthy and Falsy values?

Truthy value is boolean true and Falsy value is boolean false in javascript. you declare a variable and set value true then it is truthy or set the value false then it is falsy value. zero(0), empty string(‘’/””), null, undefined, NaN it set the falsy so you can set this value then it is falsy value otherwise all are the truthy value.

![Example Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nk9j5zpi42u1by7iww0g.JPG)

2.What is Null and Undefined?

You declare a variable but you can not assign any value then it returns undefined. you print in the console a function but it is not returned anything then it is undefined. You can assign undefined in a variable then it is undefined.

![Example Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zvab38yzinkd5qdf3nln.JPG)

You declare a variable and assign the value null to this variable then it is null. you can set the null in the variable.

![Example Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ryczcr44pqm51p211o76.JPG)

3.What is Double equal(==) and Triple equal(===)?

Double equal is checked to value and triple equal is checked to value and datatype. you can assign the same value but different datatype in two variables then you check with double equal it is true but you check with triple equal it is false.

![Example Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mvgawtzjhsopysb8h9y3.JPG)

4.What is the map?

The map is a method, you can provide a callback function in map parameter and the callback function find tree parameter, the first parameter is an array element, the second parameter is array element index and the third parameter is an array.

![Example Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kn54o7p3khqi6upuyz9s.JPG)

5.What is the filter?

The filter is a method, you can provide a callback function in the filter parameter and the callback function provide the tree parameter, the first parameter is an array element, the second parameter is array element index and the third parameter is an array and you can anything in this callback function and return this element and filter method returns a new array.

![Example Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8q94jug1mdsee6enulef.JPG)

6.What is Scope?

You can declare a variable in function then you can not access this variable outside this function but you can declare a variable outside function then you can access this variable in this function. In javascript two types of scope, one is the local scope and another is the global scope.

![Example Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8q94jug1mdsee6enulef.JPG)

7.What is Closure?

The closure is an always access variable of the outer function in the inner function and the outer function has returned or call this inner function.

```
function outerFunction() {

 let number=0;

 return function () {

  number++;

  console.log(number);

 }
}

let myNumber=outerFunction();

myNumber(); // 1

myNumber(); // 2

let otherNumber=outerFunction();

otherNumber(); // 1

otherNumber(); // 2

myNumber(); // 3

otherNumber(); // 3

otherNumber(); // 4
```

8.What is bind?

bind is a method in javascript. the bind method creates a new bound function like ‘exotic object’. bind is adding a function in an object.

![Example Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pq7jdcur1qtpbr4dw26h.JPG)

9.What is a Global Variable?

Global variable in javascript is declared outside the function and modules and this variable access in any function. you can declare a variable but you not use a keyword(let/const/var) then it is a global variable but isn’t the right way.

![Example Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/77rj9j9q2cwcd9b857rv.JPG)

10.How to remove a duplicate item from an array?

First, you can declare two arrays one is a number array and one is newNumber empty array. you can get the number array element then check this element available in newNumber array, Is it available they can't add this element otherwise add this element in newNumber array.

![Example Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jt6rzd3zzp62c6ks9skj.JPG)