Top 50 Javascript Interview Questions by Team MTA India

Top 50 Javascript Interview Questions by Team MTA India

This JavaScript Tutorial helps you learn the JavaScript programming language from scratch quickly and effectively.

Are not sure where to start learning JavaScript. Are frustrated with copy-n-paste JavaScript code from others without really understanding it. Cannot add richer and more compelling features to your websites and web applications using JavaScript because you don’t know how to get much out of the language. MTA India is a good place to start.

Q1. What different types of data are available in javascript?

Ans. To determine the JavaScript variable type, we may use the operator type.

typeof operator.

String – Represents a series of  letters and is written with quotations. The character unit can be represented using one or two quotes.


var str = “Vivek Singh Bisht”; // using two quotes

var str2 = ‘John Doe’; // using single quotes

Number – Represents a number and can be written with or without decimals.


var x = 3; // without decimal

var y = 3.6; // by decimal

BigInt – This type of data is used to store numbers greater than the Number data type limit. It can store large numbers and is represented by adding an “n” to a whole number.


Var bigInteger = 234567890123456789012345678901234567890;

Boolean – Represents a sensible business and can only have two values: true or false. Booleans are often used for conditional testing.


var a = 2;

var b = 3;

var c = 2;

(a == b) // returns false

(a == c) // returns true

Unspecified – When a variable is declared but not assigned, there is an unspecified value and its type is also not defined.


episode x; // x value not specified

var y = unspecified; // we can also set the variable value as unspecified

Null – Represents a missing or invalid value.


var z = null;

Symbol – A new type of data introduced in the ES6 version of javascript. Used to store an unknown and unique value.


var symbol1 = Symbol (‘symbol’);

genre type:

typeof “John Doe” // Returns “string”

typeof 3.14 // Returns “number”

typeof true // Returns “boolean”

typeof234567890123456789012345678901234567890n // Returns


typeof undefined // Returns “unspecified”

typeof null // Returns the “object” (JavaScript type of bug)

token type (‘token’) // Returns Token

Non-traditional types

Older data types can only store one value. To store large amounts of complexity, non-traditional types of data are used.

Item – Used to store data collection.


// Data collection in pairs of key value

var obj1 = {

x: 43,

y: “Hello world!”,

z: function () {

replace this.x;



// Data collection as a sorted list

var array1 = [5, “Hello”, true, 4.1];

* Note- It is important to remember that any type of data other than the old data type, is the Object type in javascript.

Q2. Define Hoisting in javascript.

Ans. Hoisting is a javascript default behavior where all the variables and job announcements are moved upwards.

This means that no matter where the variables and functions are advertised, they are distributed over a wide range. The scope can be both

local and global.

Example 1:

hoistedVariable = 3;

console.log (hoistedVariable); // 3 results even when the variable is announced after launch


Example 2:

hoistedFunction (); // Results “Hello world!” Even if the job is announced after a call

functionhoistedFunction () {

console.log (“Hello world!”);


Example 3:

// Raising occurs in the local area as well

functiondoSomething () {

x = 33;

console.log (x);

episode x;


do something(); // Output 33 as the “x” area variable is raised within the local scope

** Note – Variable launches are not recommended, only variable announcements are raised:

episode x;

console.log (x); // The “unspecified” results from the start of the word “x” were not suggested

x = 23;

** Note – To avoid overlapping, you can use javascript in solid mode by using “use solid” over code:

“use hard”;

x = 23; // Provides an error as ‘x’ has not been announced

episode x;

Q3. Differences between operators “==” and “===”.

Ans. Both are comparative users. The difference between the two operators is, that “==” is used to compare prices, and, “===“ is used to compare both value and type.


var x = 2;

var y = “2”;

(x == y) // Returns the truth as your value for both x and y is the same

(x === y) // Returns false as type x is “number” and type y is “string”

Q4. Define Invalid Type Forces in javascript.

Ans. Invalid type in javascript automatic conversion of value from one type of data to another. Occurs when expression operands are a different type of data.

String force

Cord enforcement occurs while using the ‘+’ operator. When a number is added to a call, the number type is always changed to the character unit type.

Example 1:

var x = 3;

var y = “3”;

x + y // Returns “33”

Example 2:

var x = 24;

var y = “Hello”;

x + y // Returns “Hello”;

** Note – ‘+’ the operator when used to add two numbers, removes the number. When the same ‘+’ operator is used to add two wires, it produces an integrated character unit:

var name = “Vivek”;

var surname = “Bisht”;

name + surname // Returns “VivekBisht”

Let’s understand both examples where I added a number to a character unit,

When JavaScript detects that the x + y expression operands are different types (one is a number type and the other is a character unit), it converts a number type to a character unit type and performs a function. After conversion, both variables are a type of character unit, the ‘+’ operator releases the combined character unit “33” in the first instance and “Hello” in the second example.

** Note – Compulsory type also occurs when using the ‘-‘ operator, but the difference when using the ‘-‘ operator is, that the series is converted to a number, and then deleting occurs.

var x = 3;

var y = “3”;

x -y // Replaces 0 as they (variable unit type) are converted to a

type of number

Boolean Coercion

The dream coercion occurs when using sensible operators, ternary operators when the statements, and loop check. To understand boolean enforcement when statements by users, we need to understand true and false values.

True values ​​are those that will be converted (forced) into reality. False values ​​are those that will be exchanged for falsehood.

All values ​​except false, 0, 0n, -0, “, null, undefined, and NaN values ​​are true.

If the statements:


Var x = 0;

var y = 23;

if (x) {console.log (x)} // The code within this block will not work as x value is 0 (False)

if (y) {console.log (y)} // The code within this block will work as the value of y is 23 (True)

Sensible operators:

Operators are logical in javascript, unlike operators in other system

languages, neither true nor false. They always come back with one

job. OR (| |) operator – If the first value is true, the original value is returned. If not, always the second value is refunded.

AND (&&) operator – If both values ​​are correct, always the second

value is refunded. If the first value is false then the first value is returned or if the second value is false then the second value is returned.


var x = 220;

var y = “Hello”;

var z = unspecified;

x || y // Returns 220 as the first value is true

x || z // Returns 220 as the first value is true

x && y // Returns “Hello” as both values ​​are true

y && z // Returns undefined as the second value is false

if (x && y) {

console.log (“Code is active”); // This structure is active because x && y returns “Hello” (True)


if (x || z) {

console.log (“Code is active”); // This block works because x || y is back

220 (True)


Enforcing Equality

Enforcement equation occurs when using ‘==’ operators. As we have said before

The ‘==’ operator compares prices and not types.

Although the above statement is an easy way to describe == operators, it is not entirely true

The fact is that while using the operator ‘==’, forcing occurs.

The ‘==’ operator, converts both operands to the same type and compares them.


var a = 12;

var b = “12”;

a == b // Returns the truth because both ‘a’ and ‘b’ are converted to the same type and then compared. So the operands are equal.

Enforcement does not happen when using ‘===’ operators. Both operands are not converted to the same type in the ‘===’ operator.


var a = 226;

var b = “226”;

a === b // Returns lies because coercion does not occur and operands are of different types. So they are not partners.

Q5. Is javascript a statically typed or a dynamically typed language?

Ans. JavaScript is a dynamically typed language. In a dynamically typed language, the type of a variable is checked during run-time in contrast to a statically typed language, where the type of a variable is checked during compile-time.

Since javascript is a loosely(dynamically) typed language, variables in JS are not associated with any type. A variable can hold the value of any data type.

For example, a variable that is assigned a number type can be converted to a string type:

var a =23;

var a =”Hello World!”;

Q6. What is NaN in JavaScript?

Ans. The NaN structure stands for “Not-a-Number”. Displays a value that is not an official number.

NaN type will return Number.

To check the value of NaN, we use the isNaN () function,

** Note- isNaN () function converts a given value into a Number type, and then equal to NaN.

isNaN (“Hello”) // Returns the truth

isNaN (345) // Returns lies

isNaN (‘1’) // Returns lies, as ‘1’ is converted to a number type

leading to 0 (number)

isNaN (true) // Returns false, as truth translated into Number type exit to 1 (number)

isNaN (false) // Returns false

isNaN (not defined) // Returns the truth

Q7. Explain how to approve and approve the reference.

Ans. In JavaScript, classified data types are transferred and non-classic data types are referenced.

To get a better understanding of the value and beyond the reference, we need to understand what happens when we create a variable and value it,

var x = 2;

In the example above, we created a variable x and gave it a value of “2”. In the background, “=” (assign operator) allocates some space to memory, saves the value of “2” and returns the space of shared memory space. 2 directly.

Assign operator behavior differently when dealing with older and non-old data types,

Assign an older version operator:

var y = 234;

var z = y;

In the example above, the supplied operator knows that the value assigned to y is an old form (number type in this case), so when the second-line code makes when the value of y is assigned to z, the distributing operator takes the value. of y (234) and provide a new space in memory and restore the address. Therefore, variable z does not indicate the location of the variable y, instead, it indicates a new location in memory.

var y = # 8454; // y pointing to a value address 234

var z = y;

var z = # 5411; // z pointing to a completely new address of 234 value

// Changing the value y

y = 23;

console.log (z); // Returns 234, as z points to the new address in memory so changes to y will not work z

From the example above, we can see that old data types when transferred to other variables, are transferred in value. Instead of simply assigning the same address to other variables, the value is transferred and a new memory is created.

Assign a non-traditional operating operator:

varobj = {name: “Vivek”, surname: “Bisht”};

var obj2 = obj;

In the example above, the supplier operates, directly passing the variable obj location to the variable obj2. In other words, the variable obj reference is transferred to variable obj2.

varobj = # 8711; // obj pointing address {name: “Vivek”, surname: “Bisht”}

var obj2 = obj;

var obj2 = # 8711; // obj2 pointing to the same address

// to change the value of obj1 = “Akki”;

console.log (obj2);

// Returns {name: “Akki”, surname: “Bisht”} as both variables point to the same address.

From the example above, we can see that while transferring non-traditional data types, the provider is directly passing the address (index).

Therefore, non-traditional types of data are often transmitted by reference.

Q8. What is the Quickest Request for JavaScript?

Ans. Immediate Requested Work (also known as IIFE and also called IIFY) is a function that works as soon as it is defined.

IIFE syntax:

(function () {

// Do something;

}) ();

To understand the IIFE, we need to understand two sets of brackets that were not added during the construction of the IIFE:

The first set of brackets:

(function () {

//Do something;


When we use the javascript code, whenever a moderator sees the word “function”, you think we are declaring a function in the code. So, if we do not use the first set of brackets, the producer makes a mistake because he thinks we are announcing the work, and with the syntax of announcing the work, the work should always have a name.

function () {

//Do something;


// Composer provides an error as the job announcement syntax is

wrong in the code above.

To correct this error, add the first set of brackets that tells the compiler that the function is not a job announcement;

activity indicator.

The second set of brackets:

(function () {

//Do something;

}) ();

From the definition of IIFE, we know that our code should work as soon as it is defined. The function only works when requested. If we do not apply for a job, the job announcement is returned:

(function () {

// Do something;


// Returns the job announcement

So to request a job, we use the second set of brackets.

Q9. Define Advanced Editing Tasks in javascript.

Ans. Jobs that work in other jobs, by taking them as arguments or giving them back, are called high-level jobs.

Advanced jobs are the result of javascript first-class citizenship activities.

Examples of high-level jobs:

functionhigherOrder (fn) {

fn ();


higherOrder (function () {console.log (“Hello world”)});

Top functionOda2 () {

returnfunction () {

replace “Do something”;



var x = higherOda2 ();

x () // Returns “Do something”

Q10. Define the keyword “this”.

Ans. The keyword “this” refers to what a function is


The value of the “this” keyword will always depend on the request request.

Confused? Let’s understand the above statements with examples:

functiondoSomething () {

console.log (this);


do something();

The keyword “this” refers to what the function is part of.

In the code above, the function is the structure of what object?

As work is requested in the context of the world, work is the property of a global object.

Therefore, the issuance of the above code will be a global phenomenon. Since we used the code above inside the browser, the global object is a window object.

Example 2:

varobj = {

Name: “vivek”,

getName: function () {

console.log (;



obj.getName ();

In the code above, during the request, the getName function is part of the object, therefore, this keyword will refer to the object, so the output will be “Vivek”.

Example 3:

varobj = {

Name: “vivek”,

getName: function () {

console.log (;



vargetName = obj.getName;

var obj2 = {name: “akshay”, getName};

obj2.getName ();

Can you guess the output here?

The output will be “Akshay”.

Although the getName function is declared within the obj object, at the time of the request, getName () is the obj2 location, so the keyword “this” will refer to obj2.

The foolish way to understand this keyword is, whenever a job is asked, check something before the dot. The. The key will remain the object before the dot.

If there is no object before the dot as in the example1, the value of this keyword will become a global object.

Example 4:

var obj1 = {

address: “Mumbai, India”,

getAddress: function () {

console.log (the. address);



vargetAddress = obj1.getAddress;

var obj2 = {name: “akshay”};

obj2.getAddress ();

Can you guess the output?

The output will be an error.

Although in the code above, this keyword refers to something obj2, obj2 has no ‘address’ ’, which is why the getAddress function throws an error.

Q11. Define dial (), use () and, (bind) () methods.

Ans. call ()

It is the method previously described in javascript.

This method calls the method (function) by specifying the object of the owner.

Example 1:

FunsayHello () {

return “Hello” +;


varobj = {name: “Sandy”};

says Hello. call (obj);

// Returns “Hello Sandy”

call () method allows an object to use the object (function) of another object.

Example 2:

living person = {

age: 23,

getAge: function () {

return this.the years;



var person2 = {age: 54}; (person2);

// Returns 54

call () accepts arguments:

FunsaySomething {message) { + “says” + message;


var person4 = {name: “John”}; (person4, “awesome”);

// Returns “John is amazing”

use ()

The input method is the same as the call () method. The only difference is,

call () method takes issues separately while applying () method takes arguments as a system.

FunsaySomething {message) { + “says” + message;


var person4 = {name: “John”};

saySomething.use (person4, [“awesome”]);

bind ()

This method returns a new function, in which the value of the keyword “this” will be tied to the object, which is provided as a parameter.

Example with arguments:

varbikeDetails = {

displayDetails: function (registrationNumber, brandName) { + “,” + “Bike details:” + registration number + “,” + brandName;



var person1 = {name: “Vivek”};

var detailsOfPerson1 = bikeDetails.displayDetails.bind (person1, “TS0122”, “Bullet”);

// Responsible for display functionDetails for personal item1

Personal details1 ();

// Restores Vivek, bike details: TS0452, Thunderbird

Q12. What is currying in JavaScript?

Ans. Currying is an advanced technique of converting the work of arguments n, into n the work of one or fewer arguments.

Example of curried work:

add function (a) {

returnfunction (b) {

replace a + b;



add (3) (4)

For example, if we have the function f (a, b), then the function after conversion, will be converted to f (a) (b).

By using a currying method, we do not change the functionality of the function, we simply change the way it is used.

Let’s see how curry works:

function duplicates (a, b) {

replace a * b;


currying function (fn) {

returnfunction (a) {

returnfunction (b) {

returnfn (a, b);




varcurriedMultiply = currying (repetition);

repeat (4, 3); // Returns 12

curriedIncrease (4) (3); // And returns 12

As one can see from the code above, we have converted the multiplication function (a, b) into a curriedMultiply function, which takes one parameter at a time.

Q13. Define Scope and Scope Chain in javascript.

Ans. Scope in JS determines the availability of flexibility and functions in various parts of the human code.

Generally, the scope will inform us in a particular section of the code, what variables and functions we can or cannot achieve.

There are three types of scopes in JS:

Global Scope

Location or Scope of Work

Block Width

Global Scope

The variables or functions announced in the global namespace have a wide range of globes, which means that all variables with globally wide functions can be accessed anywhere within the code.

varglobalVariable = “Hello world”;

functionendMessage () {

returnglobalVariable; // can access globalVariable as it is written in the earth’s atmosphere


function sendMessage2 () {

returnsendMessage (); // Can access sendMessage function as it is written in the atmosphere


sendMessage2 (); // Returns “Hello world”

Scope of Work

Any variables or functions declared within a function have a range of area/function, which means that all variables and functions specified within the function, can be accessed within the function and not outside of it.

functionawesomeFunction () {

var a = 2;

var multiplyBy2 = function () {

console.log (a * 2); // Can access the “a” variable as a and multiplyBy2 are both written within the same function



console.log (a); // Casts a reference error as a is written in the width of the area and cannot be accessed externally

repeat2 (); // Casts a reference error as multiplyBy2 is written in the local program

Block Width

The block scope is related to the variables announced using let and const. The variables declared by var do not have block scope.

The block scope tells us that any variables declared within the block {}, can only be accessed within that block and cannot be accessed without it.


allow x = 45;


console.log (x); // Provides reference error as x cannot be accessed outside the block

for (let i = 0; i <2; i ++) {

// do something


console.log (i); // Provides reference error because I cannot be reached without a loop block

Scope Chain

JavaScript Engine also uses Scope to detect variables.

Let’s understand that we use an example:

var y = 24;

functionfavFunction () {

var x = 667;

varanotherFavFunction = function () {

console.log (x); // It does not find x inside another FavFunction, so it looks for variables within favFunction, output 667


varyetAnotherFavFunction = function () {

console.log (y); // Can’t find y inside yetOneFavFunction, so it looks for variables within favFunction and does not find it, so it looks for variables across the earth, find and exit 24


anotherFavFunction ();

of OneFavFunction ();


favFunction ();

As you can see in the code above, if the javascript engine does not find a variable in the width range, it tries to check the variable in the external width. If the variable is not in the external scope, it attempts to detect the variable across the earth’s surface.

If the variable is not found in the Earth field again, the reference error is thrown away.

Q14. What is a model chain?

Ans. Prototype chaining is used to create new types of objects based on existing ones. It is like a legacy in a classroom-based language.

The prototype for the object model is found in the Object.getPrototypeOf (object) or ** proto ** material while the prototype in the builder function is found in the Object. prototype.

Q15. What is JSON and its normal operation

Ans. JSON is a text-based data format that follows the syntax of a JavaScript object, popularized by Douglas Crockford. Useful if you want to transfer data across the network and is just a text file with the .json extension, and the MIME type of application / JSON

Analysis: Converting a character unit into a native object

JSON. Analyze (text);

Integration: converting an original object into a character unit for transmission across a network

JSON.stringify (into);

Q17. What is the purpose of the array splice method

Ans. The splice () method is used to either add/remove items to/from the system and then restore the extracted item. The first argument specifies the location of the same members to be added or removed while the second optional argument indicates the number of items to be removed. Each additional argument is added to the same members.

Some examples of this method are,

let arrayIntegersOriginal1 = [1, 2, 3, 4, 5];

let arrayIntegersOriginal2 = [1, 2, 3, 4, 5];

let arrayIntegersOriginal3 = [1, 2, 3, 4, 5];

let arrayIntegers1 = arrayIntegersOriginal1.splice (0, 2); // returns [1, 2]; actual list: [3, 4, 5]

let arrayIntegers2 = arrayIntegersOriginal2.splice (3); // return [4, 5]; real list: [1, 2, 3]

let arrayIntegers3 = arrayIntegersOriginal3.splice (3, 1, “a”, “b”, “c”); // returns [4]; real list: [1, 2, 3, “a”, “b”, “c”, 5]

Note: The Splice method corrects the same original members and returns the same deleted members.

Q18. What is the difference between a piece by piece

Ans. Another major difference in table form Slice Splice

It does not change the actual program (invariant) Edits the actual program (variable)

Restores a subset of the same original members Restores deleted items as a program Used for selecting elements in a list Used to add or remove elements to/from similar members

Q19. How do you compare an object with a map?

Ans. Things are similar to Maps in that they both allow you to set value keys, retrieve those values, delete keys, and discover that something has been saved to the key. For this reason, Items have been used as historical maps. But there are important differences that make the use of the map ideal in certain situations.

Object Keys are Cables and Symbols, while they can be any Map value, including functions, objects, and any primitive.

The keys on the map are ordered while the keys are added to the Object. So, when it repeats on top of it, the Map object returns the keys in a sequence of input.

You can easily find the Map size by size, while the number of layouts in an item has to be determined manually.

A map is a duplicate and thus can be duplicated directly, while duplication on an object requires finding its keys in another fashion and duplication over them.

The object has a prototype, so there are default keys on the map that can collide with your keys if you are not careful. From ES5 this can be passed using map = Object. create (null), but this is rarely done.

The map may work best in situations involving frequent additions and removal of important pairs.

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

Ans. JavaScript provides both solid (===,! ==) and conversion (==,! =) Comparisons. Solid operators consider the type of flexibility, while weak operators perform type adjustment/conversion based on variable values. Solid operators follow sub-conditions of different types,

Two strings are the same if they have the same sequence of letters, the same length, and the same characters in the same positions.

Two numbers are equally strong when they are equal in numbers. that is, Having the same number value. There are two special cases in this regard,

NaN is not equal to anything, including NaN.

The zeros are both positive and negative.

The two Boolean operands are equally solid if both are true or both are false.

Two things are equal when referring to the same thing.

Empty and unspecified types are not equal to ===, but are equal to ==. that is, null === undefined -> false but null == undefined -> true

One example includes the cases above,

0 == false // true

0 === false // false

1 == “1” // true

1 === “1” // false

null == unspecified // true

null === unexplained // false

‘0’ == false // true

‘0’ === false // false

[] == [] or [] === [] // false, refer to different things in memory

{} == {} or {} === {} // false, refer to different things in memory

Q21. What are the functions of lambda or arrow?

Ans. Arrow function is a short syntax of a function sentence and does not have its own, arguments, super, or new. target. These works are best suited for non-road work, and cannot be used as builders.

22. What is the function of the first phase?

In Javascript, tasks are first-class objects. The first category of functions means when the functions of that language are treated like any other dynamics.

For example, in such a language, a function can be transferred as an argument to other functions, may be returned by another function, and may be given as a variable value. For example, in the example below, the host functions assigned to the listener

const handler = () => console.log (“This is the function of the click handle”);

document.addEventListener (“click”, holder);

Q23. What is the function of the first order?

Ans. The first-order function is a function that does not accept another function as an argument and does not return the function as its return value.

constfirstOrder = () => console.log (“I’m the first order function!”);

Q24. What is high-quality work?

Ans. A high order function is a function that accepts another function as a conflict or returns a function as a return value or both.

constfirstOrderFunc = () =>

console.log (“Hello, I am a First Order function”);

consthigherOrder = (ReturnFirstOrderFunc) => ReturnFirstOrderFunc ();

highOrder (firstOrderFunc);

Q25. What is an unusual activity?

Ans. The work of the Unary (i.e., monadic) is a work that receives one argument. Represents one argument accepted for the job.

Let us take the example of unary work,

contunaryFunction = (a) => console.log (a + 10); // Add 10 to the given argument and show value

Q26. What is currying?

Ans. Currying is a process of taking on a task with multiple arguments and making it a series of tasks each with only one argument. Currying is named after mathematician Haskell Curry. By using currying, the n-ary function converts it into abnormal activity.

Let’s take an example of n-ary work and how it turns into a work of art,

constmultiArgFunction = (a, b, c) => a + b + c;

console.log (multiArgFunction (1, 2, 3)); // 6

constcurryUnaryFunction = (a) => (b) => (c) => a + b + c;

curryUnaryFunction (1); // returns function: b => c => 1 + b + c

curryUnaryFunction (1) (2); // returns function: c => 3 + c

curryUnaryFunction (1) (2) (3); // returns the number 6

Curried functions are good for improving code usability and performance.

Q27. How to re-declare variable  blocks without error?

Ans. If you try to re-announce the variable in the switch block it will create errors because there is only one block. For example, the block code below throws in syntax error as below,

allow calculator = 1;

change (x) {

case 0:

allow name;

break time

case 1:

allow name; // Syntax error for re-announcement.

break time


To avoid this error, you can create an enclosed block within a rule clause and create a new scoped block dictionary.

allow calculator = 1;

change (x) {

case 0: {

allow name;

break time


case 1: {

allow name; // No Syntax Error for re-announcement.

break time



Q28. What is the Temporal Dead Zone?

Ans. Temporal Dead Zone is a JavaScript behavior that occurs when a variable is announced with let and const keywords, but not with var. In ECMAScript 6, access to a let or const variable before its declaration (within its scope) triggers the ReferenceError. The length of time that happens, between the creation of a variable commitment and your declaration, is called a temporary deadline.

Let’s look at this behavior by example,

functionsomemethod () {

console.log (counter1); // unspecified

console.log (counter2); // ReferenceError

var counter1 = 1;

enable counter2 = 2;


Q29. What is IIFE (Immediately Invoked Function Expression)?

Ans. IIFE (Immediately Invoked Function Expression) is a JavaScript function that works as soon as it is defined. Its signature will be as follows,

(function) {

// logic here

}) ();

The main reason for using IIFE is to obtain data privacy because any of the variables declared within the IIFE cannot be accessed by a foreign country. that is, if you try to access the variable with IIFE and drop the error as below,

(function) {

var message = “IIFE”;

console.log (message);

}) ();

console.log (message); // Error: message not defined

Q30. How do you remove a URL from JavaScript?

Ans. The encodeURI () function is used to encrypt the URL. This function requires a unit of URLs as a parameter and then returns that encrypted unit. The decode URI () function is used to record a URL. This function requires a character unit of a URL with a code as a parameter and then returns that unlocked letter character.

Note: If you want to code characters like /? : @ & = + $ # then you need to use the encodeURIComponent ().

leturi = “empployeeDetails? name = john & occupation = manager”;

letencoded_uri = encodeURI (uri);

letdecoded_uri = decodeURI (encoded_uri);

Q31. What is memorization?

Ans. Memoization is a programming program that attempts to maximize the performance of a project by archiving its computer-generated results. Each time a manual task is called, its parameters are used to identify the repository. If the data is available, then it can be restored, without doing all the work. Otherwise, the function is executed and the result is added to the repository. Let’s take the example of adding a task by heart,

constmemoizAddition = () => {

enable repository = {};

return (value) => {

if (value in cache) {

console.log (“Downloading cache”);

restore repository [value]; // Here, cache.value cannot be used as the domain name starts with a number that is not a valid JavaScript index. Therefore, it can only be achieved using square bracket notation.

} more {

console.log (“Calculation effect”);

allow result = value + 20;

repository [value] = result;

restorative effect;




// function restored from memoizAddition

Const then = memoizAddition ();

console.log (add (20)); // output: 40 included

console.log (add (20)); // output: 40 cache

Q32. What are you hoisting?

Ans. Hoisting is a JavaScript machine in which variables, work announcements, and classes are moved over a wide range before the code is released. Remember that JavaScript only supports ads, not implementation. Let’s take a simple example of variable hoisting,

console.log (message); // output: unspecified

var message = “Variables suggested”;

The code above appears below the translator,

var message;

console.log (message);

message = “Variables suggested”;

In the same way, performance announcements are also raised

message (“Hello”); // Hello

job message (name) {

console.log (name);


This suggestion allows the functions to be safely applied to the code before it is announced.

Q33. What are the classes in ES6?

Ans. In ES6, Javascript classes are primarily a sugar made up of an existing JavaScript prototype asset. For example, a prototype based on the work done below,

Active bike (model, color) {

this.model = model;

this.color = color;


Bike.prototype.getDetails = function () {

returnthis.model + “bike has” + this.color + “color”;


Although ES6 classes can be described as an alternative

Class Bike {

builder (color, model) {

this.color = color;

this.model = model;


getDetails () {

returnthis.model + “bike has” + this.color + “color”;



Q34. What is closure

Ans. Closing the combination of the function and the nature of the dictionary in which that function was declared. that is, it is an internal function with access to the external or closed function of the function. The closure has three wide chains

His scoop where the distinction is defined between its curved brackets

Flexible for external work

Global variables

Let’s take the example of the concept of closure,

Welcome function (name) {

vargreetingInfo = function (message) {

console.log (message + “” + name);




varmyFunction = Welcome (“John”);

myFunction (“Welcome”); // Output: Welcome John

myFunction (“Hello Sir”); // outgoing: Hello Mr. John

As per the code above, the internal function (i.e., greetingInfo) has flexible access to the external application (i.e., Welcome) even after the external function is back.

Q35. What are modules?

Ans. Modules refer to small units of independent code, that are reusable and serve as the basis for many JavaScript design patterns. Most JavaScript modules send the actual object, function, or builder

Q36. Why do you need modules?

Ans. Below is a list of benefits of using modules in the javascript ecosystem



Word space

Q37. What is the scope for javascript?

Ans. The scope is the availability of flexible objects, functions, and objects in a particular part of your code during operation. In other words, scope determines the visibility of variables and other resources in the areas of your code.

38. What is a service worker file?

Ans. The Service Worker is a background (JavaScript file) that runs in the background, separates a web page, and provides features that do not require a web page or user interaction. Some of the key features of the service staff are Offline Rich Experience (first offline web application development), periodic background synchronization, app notifications, blocking and managing network requests, and system responsive management.

Q39. How to cheat DOM using a service provider?

Ans. The service provider cannot access DOM directly. But it can communicate with the pages it manages by replying to messages sent through the postMessage interface, and those pages can deceive DOM.

Q40. How to reuse information in all service provider restart?

Ans. The problem with the service provider is that it is disconnected when not in use, and restarted when needed next, so you cannot rely on global status within the service server download and message holders. In this case, service staff will be able to access the IndexedDB API to continue and re-use all reboots.

Q41. What is IndexedDB?

Ans. IndexedDB is a low-level client-side-client API for large amounts of organized data, including files/blocks. This API uses references to enable the most effective search for this data.

Q42. What is a web storage?

Ans. Web storage is an API that provides a way for browsers to store key pairs/values ​​locally within a user’s browser, in a more accurate way than using cookies. Web storage offers two ways to store data for a client.

Local storage: We store current source data without an expiration date.

Time Storage: We save data for one session and data is lost when the browser tab is closed.

Q43. What is the message of the post?

Ans. Post message is a method that creates different source connections between window objects. Generally, texts on different pages are allowed to access one another if and only if the pages follow the same source policy (i.e., pages sharing the same protocol, port number, and host).

Q44. What is a Cookie?

Ans. A cookie is a piece of data stored on your computer for your browser to access. Cookies are stored as key pairs/values. For example, you can create a cookie named after us as below,

document.cookie = “username = John”;

Q45. Why do you need a cookie?

Ans. Cookies are used to remember information about a user profile (such as a username). It involves two steps,

When a user visits a web page, the user profile may be stored in a cookie.

The next time a user visits a page, the cookie remembers the user profile.

Q46. What options in a cookie?

Ans. There are a few options below for cookies,

By default, the cookie is deleted when the browser is closed but you can change this behavior by setting the expiration date (during UTC).

document.cookie = “username = John; expires = Sat, 8 Jun 2019 12:00:00 UTC”;

By default, the cookie belongs to the current page. But you can tell the browser what the cookie is like using the path parameter.

document.cookie = “username = John; path = / services”;47.How to delete a cookie

You can delete cookies by setting the expiration date as the expiration date. You do not need to specify a cookie value for this. For example, you can delete the username cookie from the current page as below.

document.cookie =

“username =; expires = Friday, 07 Jun 2019 00:00:00 UTC; route = /;”;

Note: You must define a cookie path option to ensure that you delete the correct cookie. Some browsers do not allow you to delete cookies unless you specify a path parameter.

Q48. What is the difference between a cookie, local storage and session save?

Ans. Below are the differences between a cookie, location, and session storage,

Install Cookies Local Storage Session Storage

Client or client-side Access Both server-side and client-side – client-side only

Lifetime Asset using the Expiration option until the tab closes

SSL Support Supported Not Supported

Data size limit 4KB 5 MB 5MB

Q49. What is the main difference between Location Storage and Saving Stage?

Ans. LocalStorage is similar to SessionStorage but persists in data even when the browser is closed and reopened (i.e. has no expiration time) and in the sessionStorage data is erased when page time expires.

Q50. How to get into a web storage?

Ans. The Windows object uses Windows WindowLocalStorage and WindowSessionStorage features LocalStorage (window.localStorage) and sessionStorage (window.sessionStorage) respectively. These properties create an example of a Storage object, in which data objects can be set, retrieved and extracted from a specific domain and type of storage (session or location). For example, you can read and write to the last items in the area as below

localStorage.setItem (“logo”, document.getElementById (“logo”). value);

localStorage.getItem (“logo”);

MTA India is a leading IT Training and Internship company in Noida, Greater Noida and NCR which provides 6 Months training in several evergreen technologies. This training is offered in Noida, Greater Noida, and NCR.

Register with MTA India @

Facebook page –

Industrial Training :

Instagram page –

Website |

By Microdot Tech Aspire Solutions(P) Ltd.Meet @ | A-93, Sector 4 Near Sector 16 metro station, Noida, Uttar Pradesh 201301.

Leave a Reply

Your email address will not be published. Required fields are marked *