JavaScript Interview Questions - Collection-1

What is JavaScript?


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

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

MULTI-PARADIGM means We can use diffrent styles of programming like impretive and declartive programming

What is 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 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 the HTML elements.

What is event propagation?

Event Propagation is the mechanism which defines how the event travel through the DOM tree to arive 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 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

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, function expressions are not hoisted. Is that true?


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 strict mode?

Strict mode is a special mode that we can activate in Javscript,which makes it easiaer for us to write a secure javascipte code.

'use strcit' in begginig of file is used to activate strcit mode in javascipt file

First, strct mode forbds us to do certain things and seconds, it will actually create visible erros for us in certain situations in which without strct mode javascript will simply fail silenlty without letting us know that we did a mistake.

// Activating Strict Mode

let hasDriversLicense = false;

const passTest = true;

if (passTest) hasDriversLicense = true;

if (hasDriversLicense) console.log('I can drive :D');

// const interface = 'Audio';

// const private = 534;