important Question of javascript

MAHMUD SUFIAN
4 min readMay 8, 2021

1. truthy and falsy

all numbers are other than 0. and all strings are true other than an empty string. undefined is falsy. null, NaN, false is falsy value. after that, all numbers are true values and all strings true values and true is true value. white space is a truth value an empty object and an empty array is a truth value.

2. null VS undefined

we can take undefined value in some systems. first of all, we can set an undefined then we can get an undefined value and we can call object property but this property not uses then we can get undefined. and when we can not set the value but this variable is called then we can get undefined. function value does not return then this is undefined. when any function expects the two values but we can pass the one value then this is the undefined. after that null is falsy value. always we can set the null value.

3. equal (=, ==, ===)

equal is the most important question. single (=) equal is work by assigning the value. and double (==) equal works by conditionally check the value between two variables. not check the data type. after that, triple (===) equal Is a conditional check of the two variables. these are checking the value and data type.

4. var, let, and const

var and let are global scope variables. but any function or (if) block included let and var then these variable not access the outside of (if) block. var is accessed because var will be hoisted. hoisted means when code scene then finds the var and that var catch and new position of parent level. that's why var is accessible but let is not hoisted. that's why let is not accessible. after that let and const are similar but the let value is changeable but the const value is fixed. when we cant set the const value then the const value is not changeble.

5. closure

the closure is the most common important question in javascript. when one function has another function. and return or use another function then these functions are the closest environment. and these have external value.

6. bind, call and apply

when one object or class property passes another object or class then we can use the bind, call and apply method. bind not directly uses. but bind one-time call then some time pass the parameter. after that, call and apply is similar. but call and apply directly usable. but call have always two arguments. the first argument is the new object name and the second argument is that the expected parameter and these parameters are comma separated. after that, apply method is the same but the argument system is changing. the first argument is the new object name and the second argument is the expected parameter but these parameters surrounding the array.

7. this keyword

this keyword is the oldest use but right now some time uses. but important of interview question. where object or class has this keyword and that (this) is means by the parent object. and every time this always presents the parent object.whatever goes to object.

8. setTimeout and setInterval

javascript is asynchronous but we can take the synchronously. we can use the setTimeout then this is the make of synchronous. set timeout is just one time call and this is the last time call. every code executes then setTimeout execute. after that setInterval is similar but this is the infinity execute. but set the interval time.

9. max number in an array

any array have some values and this array will loop then we can get the single element and this element and default max value conditionally compare . then we can get the max value in the array.

EXAMPLE:

const arrayMax = (num) => {

let max = num[0];

num.forEach(element => {

if(element > max){

max = element;

}

});

return max;

}

const numbers = [77, 34, 73, 16, 39, 83, 30, 93];

const result = arrayMax(numbers);

console.log(result); // expected output: 93

console.log(Math.max(…numbers)); // expected output: 93

10. remove duplicate number in an array

any array has some values and this array will loop then we can get the single element and this element and default empty array conditionally compare. then we can remove the duplicate value in the array.

EXAMPLE:

const duplicate = (num) => {

let uniqueArray = [];

num.forEach(element => {

const index = uniqueArray.indexOf(element);

if(index == -1){

uniqueArray.push(element);

}

});

return uniqueArray;

}

const numbers = [77, 34, 73, 1, 4, 16, 39, 77, 83, 30, 1, 4, 93, 93];

const result = duplicate(numbers);

console.log(result);

// expected output: [ 77, 34, 73, 1, 4, 16, 39, 83, 30, 93 ]

--

--