DEV Community

Fazle Rabbi
Fazle Rabbi

Posted on • Updated on

javascript most common interview questions

1. Explain javascript Truthy and Falsy values

In a conditional statement (if, else), usually, we use boolean values true and false. Ture value is known as truthy and false value is known as falsy.

Truthy and falsy value

Truthy
anything that is not mentioned above
Enter fullscreen mode Exit fullscreen mode
falsy
false, '', "", 0, -0, 0n, NaN, null, undefined
Enter fullscreen mode Exit fullscreen mode

Is javascript asynchronous?
Ans: By nature, javascript doesn’t asynchronous, It’s synchronous. But it has lots of features like callbacks, promises, async/await which allows implementation of asynchronous event handling project.

different between “==” and “===”
Ans: == is used for comparing two variables, but it ignores the datatype of the variable whereas === is used for comparing two variables, but this operator also checks datatype and compares two values.

explain this keyword
Ans:The This keyword refers to the current object in a method or constructor.
The most common use of the this keyword is to eliminate the confusion between class attributes and parameters with the same name (because a class attribute is shadowed by a method or constructor parameter).
Explain Scope and Scope Chain in javascript.
Ans: Scope and scope chain are fundamental topics to understand how the javascript engine process and executes code.
To recap:
There are three types of scope: global scope, function scope and block scope
Scopes make possible to have variables with the same name without colliding with each other
Variables and objects in inner scopes are not accessible from outer scopes
Scope chain consists of the variables and objects referenceable by the execution context

What is closure in javascript
A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment). ... In JavaScript, closures are created every time a function is created, at function creation time.

6.What are the differences between null and undefined?
Ans: null is an assigned value. It means nothing. undefined means a variable has been declared but not defined yet.

7.What is event bubble? What are the benefits of event delegate?
Ans: Event bubbling is a type of event propagation where the event first triggers on the innermost target element, and then successively triggers on the ancestors of the target element in the same nesting hierarchy till it reaches the outermost DOM element or document objec

Benefits: Simplifies initialization and saves memory: no need to add many handlers. Less code: when adding or removing elements, no need to add/remove handlers. DOM modifications: we can mass add/remove elements with innerHTML and the like.

8.What are the differences between var, let and const
Ans: var declarations are globally scoped or function scoped while let and const are block scoped. var variables can be updated and re-declared within its scope; let variables can be updated but not re-declared; const variables can neither be updated nor re-declared.

9.What are the differences between normal function and arrow function?
Ans: 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, i.e arrow functions can never be used as constructor functions.

10.What are the usages of map, forEach, filter and find?
Ans: .forEach:
.forEach(), is used to execute the same code on every element in an array but does not change the array and it returns undefined.
.map():
.map() executes the same code on every element in an array and returns a new array with the updated elements.
.filter():
.filter() checks every element in an array to see if it meets a certain criteria and returns a new array with the elements that return truthy for the criteria.

Top comments (0)