10 most inportant javaScript questions & answers

Pritom Chowdhury Dip
4 min readMay 7, 2021

--

In this blog, I’m trying to cover about the some of the interview questions that a JS developer face in an interview.

Q : What is the difference between == and === ?

Ans : == are used to compare two variables. It ignores ta data type checking of those comparing variables. And === are used to check if both type and value matched in comparing two variables.

const a = 5;
const b = '5';
a == b // true
a === b // false

Q : What are truthy and falsy values in javaScript?

Ans : truthy values are something that are remarks as positive or in boolean which value is true where the falsy value is opposite of truthy value. Here are some examples of falsy values.

falsy values : 
0
""
undefined
null
NaN

Q : What is the difference between null vs undefined in javaScript ?

Ans : Undefined is unintentionally missing value of a variable where null is missing value of a variable intentionally. You can get undefined in many ways. Suppose, you define a variable without setting a value in it so it will show undefined. Or imagine you wrote a function and you return nothing from the function then it will return undefined.

Q : What is scope in javaScript ?

Ans : If you declare a variable in a function then you can not access the variable outside the function. This variable can be accessed inside the function. This is called local scope. But if any variable is defined globally outside the function then you can use the variable inside the function. This is called global scope.

Q. What is hoisting in javaScript ?

Ans : If you declare var variable into a scope, the variable is go up to its parent scope. The varibable can e accessed inside anywhere the function. But if you use const or let then you cannot access this outside the scope. This is called hoisting.

Q. What is closure ?

Ans : When you declare a variable in a function, you can only access it in the function. These variables are said to be scoped to the function. If you define any inner function within another function, this inner function is called a closure. I mean, When i create a function inside a function or call a function inside a function, it is created a closed environment and if a function returns another function the inner function can use the variable that are defined in outer function. This is called closure.

function count(){
let countNumber = 1;
return function(){
// countNumber variable can be accessed here
return countNumber++;
}
}
const num = count();
num(); // calling the function.

Q. Bind, Call & Apply methods in javaScript ?

Ans : The bind() method attaches one or more event handlers for selected elements and returns a function. In the returned function we can pass the arguments we need. This is bind method.

Call() method is same as bind method but it doesn’t return any function. We can easily pass arguments through comma separator.

apply() method is same as bind method but it doesn’t return any function. We can easily pass arguments through array. Call and apply method runs the function immediately when bind returns a function.

Q. What is class in javaScript?

Ans : Class concepts came from object oriented programming. Its just a blueprint of building an object. Classes are a template of creating objects. This helps to create the object oriented programming concept implemented in javaScript. Before ES6 we have to write those code inside function but after introducing es6 we can write this like,

Q. This keyword in javaScript ?

Ans : In JavaScript, this keyword refers to the object it belongs to. It has different values depending on where it is used: In a function, this refers to the global object. In a function, in strict mode, this is undefined . In an event, this refers to the element that received the event. If you call a method inside an object then this refers to the object.

Q. Async/Await in javaScript ?

Ans : We know, javaScript runs synchronously. If we send a request to the external api, we don’t know when we will return the response. JavaScript code doesn’t wait for the response. It runs automatically. So we have to call the api request asynchronously by calling async await. async makes a function returns a promise. await makes a function wait for a promise.

More questions ans answers will come slowly. Stay tuned.

--

--

Pritom Chowdhury Dip
Pritom Chowdhury Dip

Written by Pritom Chowdhury Dip

javaScript(ReactJs, NodeJs) and PHP developer(Laravel, WordPress custom Theme and plugin developer.)

No responses yet