JS Frequent asked Question
Published: 2021-05-27 15:56:50

**1.Is javascript asynchronous?**
JavaScript is a synchronous, blocking, single-threaded language. That just means that only one operation can be in progress at a time.javascript is synchronous by nature but it has a lot of features like callbacks, promises, async/await which allows you to implement asynchronous event handling in your project.
**2.What are the differences between == and ===?**
The ‘==’ operator tests for abstract value equality i.e. it does the necessary type before doing the equality comparison.
But the ‘===’ operator tests for strict equality i.e it will not do the type conversion if the two values are not of the same type, when compared, it will return false.Using the triple equals, the values must be equal in type as well.
**3.Explain “this” keyword.**
“This” keyword refers to an object that is executing the current piece of code. It references the object that is executing the current function. If the function being referenced is a regular function, “this” references the global object. If the function that is being referenced is a method in an object, “this” references the object itself.

**4.Explain Scope and Scope Chain in javascript?**
In Javascript we have three types of scope: global scope, function/local scope and block scope.
**Global Scope** is a default scope, it can be  accessed anywhere in the code.
**Function scope** Created in  a function, the declarations inside the function are only accessible there.
here the global scope cannot access the inner scope.
Then **Block scope** Applicable to let and const and its space between a pair of curly braces.Declarations are only accessible inside the block
**Scope Chain**Within each execution context is a special object called a scope chain which is used to resolve variables. A scope chain is essentially a stack of currently accessible scopes, from the most immediate context to the global context.
**5.What is Closure in JavaScript.**
Closure means that an inner function always has access to the vars and parameters of its outer function, even after the outer function has returned.One important characteristic of closure is that outer variables can keep their states between multiple calls. Remember, inner function does not keep the separate copy of outer variables but it reference outer variables, that means value of the outer variables will be changed if you change it using inner function.
**6.What are the differences between null and undefined?**
Null means an empty or non-existent value. Null is assigned, and explicitly means nothing.Undefined
Undefined means a variable has been declared, but the value of that variable has not yet been defined.
**7.What is event bubble? What are the benefits of event delegate?**
Event delegation is a technique for listening to events where you delegate a parent element as the listener for all of the events that happen inside it. Bubbling is what the event itself does.Event bubbling is the propagation of an event from the element where it happened towards the root element.Event delegation makes it possible to handle events triggered by many elements in a single place.
**8.What are the differences between var, let and const?**
The JavaScript variables statement is used to declare a variable and, optionally, we can initialize the value of that variable.
for var -Variable declarations are processed before the execution of the code.
-The scope of a JavaScript variable declared with var is its current execution context.
-The scope of a JavaScript variable declared outside the function is global.
2.The let statement declares a local variable in a block scope. It is similar to var, in that we can optionally initialize the variable. The let statement allows you to create a variable with the scope limited to the block on which it is used.
It is similar to the variable we declare in other languages like Java, .NET, etc.
3.const statement values can be assigned once and they cannot be reassigned. The scope of const statement works similar to let statements.
**9.What are the differences between normal function and arrow function?**
main difference between Syntax
Arguments binding
Use of this keyword
Using a new keyword
No duplicate named parameters
Regular functions created using function declarations or expressions are ‘constructible’ and ‘callable’. Since regular functions are constructible, they can be called using the ‘new’ keyword. However, the arrow functions are only ‘callable’ and not constructible. Thus, we will get a run-time error on trying to construct a non-constructible arrow functions using the new keyword.
**10.What are the usages of map, forEach, filter and find?
When to use forEach?**
.forEach() is great you need to execute a function for each individual element in an array. Good practice is that you should use .forEach() when you can’t use other array methods to accomplish your goal. I know this may sound vague, but .forEach() is a generic tool… only use it when you can’t use a more specialized tool.
When to use map?
.map() when you want to transform elements in an array.
When to use filter?
.filter() when you want to select a subset of multiple elements from an array.
When to use find?
.find() When you want to select a single element from an array.
When to use reduce?
.reduce() when you want derive a single value from multiple elements in an array.