Javascript Interview Questions & Answers

1. What is JavaScript?

Javascript is a programming language. It is a client-side and server-side scripting language. Javascript includes all programming aspects like conditions, iteration, etc. Javascript used in building frameworks and libraries. Javascript also called object-oriented programming. It includes all functionality of Object-oriented programming. Javascript create dynamic web pages instead of static one so that client can interact with the web site and can get a better experience.

2. What are JavaScript Data Types?

Data type basically denotes what type of data can be used to work within your program. Javascript accepts six data types which are divided into three main categories primitive, composite and special. Primitive data types are basically string, number, and boolean values. And the object, array, functions are composite data types. There are some special data types like NaN and undefined which are special data types.

3. What are Arrow function?

Though we have shown an example about arrow functions in last example, let’s talk about it now. Usually while declaring a function, you had to name it first and to get a return type you had to specify that as well. But arrow functions help you to work in a easier way with less codes. Let’s see a code example, regular functions vs arrow functions

Now the same code with arrow function —

4. What are for off & for in loop?

With ES6, new types of loop came which are for/of and for/in. This helps you to loop through iterable objects. Now there is significant difference between which one to use where. The for/of loop is for iterating value of an iterable (array, string) and for/in loop is for iterating through the keys of an object.

Let’s see an example for each of them —

5. What is the difference between == & ===?

In JavaScript == is a comparison operator and === is a strict comparison operator. In simple word == compare two variables without checking their data types. But === compare two variables as well as their data types. Example: 2== “2” will give true where 2===“2” will give false.

6. What is NaN?

NaN is a property that denotes a result that is not a number. It is a property of the global object. In other words, it is a variable in the global scope. The isNaN() is a function that determines whether a value is an illegal number or not. When the function finds a value of that condition it returns true, false otherwise.

7.What is Truthy and Falsy Value?

You will find them inside of a if statement’s condition, when you want a strict true or false output from if() condition. In JavaScript if/else check the values you will give and it will return true or false. There are some values which will return false and these are called falsy values. they are: false, ‘’, “”, 0, -0, 0n, NaN, null, undefined.
And anything except these are truthy.

8.What is destructure?

ES6 introduces data destructuring that helps to unpack values from array and objects.

9.What is the difference between Null vs Undefined?

If you focus on the two names you will get a basic idea about this two. Null represents nothing. This means if you declare a variable with a value of null that means you declared a variable which has no value.
But undefined is different from this. It tells us that something is not defined. When you declare a variable without assigning a value then it will return undefined.

10. What is a closure in JavaScript?

A closure in javascript is a scope chain where the inner function has access to the variables of the outer function also has access to the global variable. It has three scopes to access variables one its own variable one is the variable of a function in which its wrap into and the other is the global variable.

A Passionate Web technology enthusiast. Curious to know new technology every day.