10 Interview Questions in Javascript

Hasib
2 min readNov 5, 2020

Truthy value of javascript

Javascript has few truthy values ,It is very important to know these for JavaScript interview questions,there are some truthy values array,object ,string ,true ,number,etc.for example

Falsy value of javascript

Javascript has also few falsy values ,there are some falsy values false,0,-0,0n,” ”,null ,undefined ,and NaN etc.

let value = null;

if(value){

console.log(true)

}else{

console.log(false)

}

Null in javascript :

The value of null represents the absence of any object value. this is javascript primitive values and this is also falsy value ;

let value = null;

Undefined in javascript:

The value of undefined represents the primitive value undefined.This is javascript primitive types.

let value = undefined;

Null vs undefined :

null is an object type but undefined is a type in javascript. when we use undefined in variable value it means declared but no value has been assigned a value. on the other hand null in an assignment value.

map function in javascript :

The map() method creates a new array. It’s working like looping.if use for loop without map you can get same output but map() method easy to use .without array you can’t use map() method .for example

let numbers = [1,2,3,4,5,6,7,8,9];

numbers.map(number =>{

console.log(number)

})

//expected output :

1

2

3

4

5

6

7

8

9

Scope in javascript :

Scope means the accessibility of variables.javascript has two types of scope “Local scope and Global scope”.javascript has functional scope .every function creates a new scope .for example

Local scope :

function add() {

let a = 10;

let b = 20;

//this variable uses in function .it’s can’t use outside of function

}

Global scope :

let a = 20;

function add(){

console.log(a);

}

//This variable can use any place in this js file

find() in javascript :

If you want to find any variable or value from an array ,find method helps you to find it .You can make like that function but this method is easy to find. For example

const numbers = [60,70,50,55,100,120,632];

const found = numbers.find(number => number === 55);

console.log(found);

//expected output : 55

filter() in javascript :

Filter method gives you a new array ,take for example you name list of array and you need to find out length of this name and you want which name length 5 you take this and create new array .in that time filter method helps you .for example

let names = [‘hasib’,’siam’,’miju’,’masum’,’junaid’];

const newNames = names.filter(name => name.length === 5)

console.log(newNames)

//expected output : [“hasib”,”masum”]

Reducer in javascript :

The reducer function takes four arguments .”accumulator,current value,current index ,source array”.reducer gives you sum whole array numbers.for example

let numbers = [1,2,3,4,5,6,7,8,9];

const reducer = (sum,singleValue) => sum + singleValue ;

console.log(numbers.reduce(reducer));

Expected output : 45

bind() in javascript :

When we use the bind() method ,it creates a new function .when we call this keyword set to the provided value ,and gives a sequence of arguments .for example

const obj = {

x:20,

myfunc: function (){

return this.x;

}

}

const unbind = obj.myfunc;

const bindvalue = unbind.bind(obj)

console.log(bindvalue())

--

--