bluehost-banner

JavaScript Interview Questions Collection-1

What is a programming language?

A programming language is basically just a tool that allows us to write code that will instruct a computer to do something

What is JavaScript?

JAVASCRIPT IS A HIGH-LEVEL, OBJECT-ORIENTED, MULTI-PARADIGM PROGRAMMING LANGUAGE.

HIGH-LEVE means We don't' have to worry about complex stuff like memory management

OBJECT-ORIENTED means Based on an object,for storing most kinds of data

MULTI-PARADIGM means We can use different styles of programming like imperative and declarative programming

What is DOM?

DOM stands for Document Object Model. It is the representation of a web page in the form of a tree structure where each node contains an object.

The objects are nothing but the HTML elements of the page. DOM can be used to access and manipulate these elements with the help of JavaScript. DOM can be thought of as a standard to add, change or delete HTML elements.

What is event propagation?

Event Propagation is the mechanism that defines how the event travels through the DOM tree to arrive at its target.

For example, if we have a link inside a div element and we have a onclick handler on the link then it will be executed as expected. But if we place the handler on the div instead of the link, and then click on the link, the handler will still be executed. This is called Event Propagation.

What’s the purpose of web workers?

To execute expensive tasks on a separate thread than the main thread.

What is event capturing?

When we click on the tag associated with the event handler, the event travels all the way from the window through the DOM tree to its target. For example, if we click on a hyperlink, then the event will pass through the html element, the body element and the div element containing that link. If any of these tags have a capturing event listener, then it will also get executed. This is called event capturing.

What is event bubbling?

This is the exact opposite of event capturing. In this case, the event will travel back from the target to the window through the DOM tree. For example, when clicked on the hyperlink it will move to the div, body element and the html element.

What is event.target?

Event Target property returns the element that triggered the event. It gives access to the properties of the element that originally triggered the event. We can access the properties of the element using event.target.propertyName.

What’s the difference between setTimeout() and setInterval()?

setTimeout executes once after a specified time has elapsed.

setInterval executes repeatedly with a given delay between executions.

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

What’s the difference between importing a default export, named, and a non-deafult export?

Curly braces.

Function declarations are hoisted, and function expressions are not hoisted. Is that true?

Yes

How does the Maximum Call Stack Exceeded error get executed?

While a function is recursively calling itself, the ‘Stack’ of function calls waiting to execute grows until a maximum is reached.

What is a lexical scope?

The scope of an inner function that contains the scope of the parent function.

What is the difference between undefined and null?

undefined and null both are primitive types in JavaScript. undefined means a value does not exist in the scope. null means the value is made unavailable intentionally. The type of undefined is equal to undefined and the type of null is an object.

What does the double bang(!!) do?

Returns the truth value of an object.

How does JavaScript evaluate the truth-ness or falsely-ness of a value or object in a boolean context?

Type Coercion.

What is Hoisting?

As we saw in the previous question, we were able to access ‘a’ variable before it was declared, irrespective of the value it gives. This behaviour is called Hoisting in JavaScript. Variables can be initialised before they are even declared in JavaScript. But for let and const, we get an error doing so because they lie in the temporal dead zone which is not accessible to us unless we declare them. So they are hoisted too but in a different memory location.

Why are functions called first class objects?

Functions in JavaScript can be passed as an argument to another function, assigned to a variable and returned from another function. Due to these abilities functions in JavaScript are called first class objects.

What is the difference between an argument and a parameter?

When we are declaring a function, the variables we put in between the parenthesis (), are called function parameters. On the other hand, when we are calling a function, the values passed in between the parenthesis are called arguments which eventually are assigned to the parameters of the function.

What is the strict mode?

Strict mode is a special mode that we can activate in Javascript, which makes it easier for us to write a secure javascript code.

'use strict in the beginning of the file is used to activate strict mode in the javascript file

First, strict mode forbids us to do certain things, and seconds, it will actually create visible errors for us in certain situations in which without strict mode javascript will simply fail silently without letting us know that we did a mistake.

What are all the types of Pop up boxes available in JavaScript?

Alert

Confirm and

Prompt

What is the difference between an alert box and a confirmation box?

What is a cookie

What is the main difference between localStorage and sessionStorage

What is a promise

What are the three states of promise?

What is callback hell?

What are the tools or techniques used for debugging JavaScript code

How to store boolean values in localstorage?

What is the difference between for..in and for..of?

Explain passed by value and passed by reference.

Explain Higher Order Functions in javascript.

Explain call(), apply() and, bind() methods.

What is memoization?

What is the use of a constructor function in javascript?

What are arrow functions?

Differences between declaring variables using var, let and const.

What are the rest parameter and spread operator?

What is Object Destructuring?

What is the purpose of the array slice method?

What is the purpose of the array splice method?

Can you list the 6 primitive types in JavaScript?