Javascript Interview questions

sazida lubna
5 min readMay 8, 2021

1. What are the Truthy and Falsy values in JavaScript?

  • Falsy — 0, “”, undefined, null, false, NaN.
  • Truthy- ‘0’, “ “, [], “false” , etc.

2. What is the difference between null and undefined?

  • Null- An assignment value and primitive value that represents the null, empty, or non-existent reference. It indicates the absence of a value for a variable. The type of null is an object. It is converted to zero (0) while performing primitive operations.
  • Undefined- A primitive value that is used when a variable has not been assigned a value. It indicates the absence of the variable itself. The type of undefined is undefined. It is converted to NaN while performing primitive operations.

3. What is the difference between == and === operators?

  • Double equal(==) is abstract equality. It is a comparison operator, which is used to compare values.
  • Triple equal(===) is strict equality. It returns false for the values which are not of a similar type. It checks both the type and the value.

4. Explain Implicit Type Coercion in javascript.

It is the automatic conversion of value from one data type to another. It takes place when the operands of an expression are of different data types. String coercion takes place while using the ‘ + ‘ operator. When a number is added to a string, the number type is always converted to the string type. Boolean coercion takes place when using logical operators, ternary operators if statements, and loop checks. Equality coercion takes place when using the ‘ ==’ operator.

5. What is Scope?

JavaScript’s scope is the area where we have valid access to a variable or function. There’re 3 kinds of scopes in JavaScript — global, function, and block scope.

  • Global Scope- variables or functions declared in the global namespace are in the global scope and these are accessible everywhere in our code.
  • Function Scope- variables, functions, and parameters declared within a function are accessible inside that function but no outside of it.
  • Block Scope- variables ( let, const) declared within a block {} can only be accessed within it.

6. What is “closure” in javascript?

A closure is a function defined inside another function (called parent function) and as such it has access to the variables declared and defined within its parent function’s scope. The closure has three scope chains

  • Own scope where variables defined between its curly brackets
  • Outer function’s variables
  • Global variable

7. What is Encapsulation?

Encapsulation is an attribute of an object and the process of combining data and functions into a single unit called a class. It contains all data which is hidden. That hidden data can be restricted to the members of that class. Levels are Public, Protected, Private, Internal, and Protected Internal. Public functions, which can be accessed, are called methods. In Encapsulation, the data, or state, is not accessed directly. Rather, it is accessed through those public methods (functions) which are present inside of the class.

8. What are apply, bind and call?

Apply- It calls a function with a given ‘this’ value and arguments provided as an array.

Call- It calls a function with a given ‘this’ value and arguments provided individually or arguments provided one by one.

The difference between the two is that apply takes an argument as an array, and the call takes an argument individually.

Bind- It is used to bind an object method to another object. It allows us to pass any number of arguments.

9. What is a callback?

A JavaScript callback function is a function that is passed as an argument in a function and runs inside the function where it is passed. It can be used synchronously or asynchronously.

10. What is DOM?

DOM stands for Document Object Model. It is an interface (API) for HTML and XML documents. When the browser first reads our HTML document, it creates a big object, a really big object based on the HTML document this is the DOM.

11. What is Event Bubbling?

When an event occurs on a DOM element, that event does not entirely occur on that just one element. In the Bubbling Phase, the event bubbles up or it goes to its parent, to its grandparents, to its grandparent’s parent until it reached all the way to the window.

12. What would be the output of the following code?

[ ‘100’ ]
1

13. What would be the output of the following code?

11

14. What would be the output of the following code?

undefined
true

15. What would be the output of the following code?

John

--

--

sazida lubna
0 Followers

Courteous and enthusiastic,have strong driving force for improving the performance,scalability, and reliability of development projects.