DEV Community

Cover image for 10 Javascript Interview Question
Md Rasel
Md Rasel

Posted on

10 Javascript Interview Question

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

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

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

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

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

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

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

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
Enter fullscreen mode Exit fullscreen mode

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

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

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

Top comments (0)