Javascript interview question set 2/JavaScript Interview Questions and Answers for Freshers & Experienced

Is it possible in JavaScript to proceed with automatic type conversation?

Yes, it’s possible and there is nothing much programmers have to do to access it. It is actually the most common method used by the developers when it comes to conversion

What is the use of the blur function?

Blur function is used to remove the focus from the specified object.

Are you familiar with the prompt box in JavaScript?

Yes, basically many times a programmer has to enter the input values directly through the text box. The prompt box is something that is extremely helpful for the users during such a situation. Label and the box are provided for the ease of programmers. They are basically used for entering the number or the text simply.

Which keywords are used to handle exceptions?

Try… Catch---finally is used to handle exceptions in the JavaScript

Code to throw an exception.
Code runs either it finishes successfully or after catch

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

An alert box displays only one button, which is the OK button.

But a Confirmation box displays two buttons, namely OK and cancel.

What is an undefined value in JavaScript?

Undefined value means the

Variable used in the code doesn't exist
Variable is not assigned to any value
Property does not exist

What is the function of the delete operator?

The delete keyword is used to delete the property as well as its value.

var student= {age:20, batch:"ABC"};
Delete student. age;

How to detect the operating system on the client machine?

In order to detect the operating system on the client machine, the navigator. Platform string (property) should be used.

What would be the result of 3+2+"7"?

Since 3 and 2 are integers, they will be added numerically. And since 7 is a string, its concatenation will be done. So the result would be 57.

What are all the looping structures in JavaScript?

Following are looping structures in Javascript:

a) For
b) While
c) Do-while loops

How to read and write a file using JavaScript?

There are two ways to read and write a file using JavaScript

1. Using JavaScript extensions
2. Using a web page and Active X objects

What is the working of timers in JavaScript?

Timers are used to execute a piece of code at a set time or repeat the code in a given interval. This is done by using the functions setTimeout, setInterval, and clearInterval.

The setTimeout(function, delay) function is used to start a timer that calls a particular function after the mentioned delay. The setInterval(function, delay) function repeatedly executes the given function in the mentioned delay and only halts when canceled. The clearInterval(id) function instructs the timer to stop.

Timers are operated within a single thread, and thus events might queue up, waiting to be executed.

What exactly do you know about the global variables? Which keyword do you use to declare them?

There are variables in the language that generally doesn’t have much scope or their scope is limited. In JavaScript, Global variables are the same variables. To declare them, the keyword that can be used is var. the fact is most of the programmers avoid using this variable due to a major issue and i.e. the strong chances of clashing of variable names with the global, or with the local group. F course, it leads to many issues. In addition to this, there are certain chances of debugging issues that declare their presence with the global variables.

Compare ASP Script and JavaScript in terms of speed?

When it comes to speed, both of them are powerful but both have their own limits that put them separate from one another. JavaScript is known to have a quick speed for performing similar functions. This is because JavaScript doesn’t need the help of a web server to perform the task which is assigned to it. However, ASP is slow as compare to it. This is because of the very same reason and i.e. it depends largely on the webserver for executing the tasks assigned to it. Although the server-side version of JavaScript i.e. node.js also exists, still it is known to provide quick results.

What is negative Infinity?

isNan function is useful in case the argument is not a number. Actually, it remains true if the argument doesn’t have a number while on the other side it remains false if it is.

If the argument is not a number, which function you will use in JavaScript?

isNan function is useful in case the argument is not a number. Actually, it remains true if the argument doesn’t have a number while on the other side it remains false if it is.

What are IIFEs?

IIFEs (Immediately Invoked Function Expressions), also called Self-Executing Anonymous Functions, are functions that execute immediately after their definition. These are also a design pattern that contains two major parts:

The first part is an anonymous function with a lexical scope enclosed within the Grouping operator (). This restricts the access of variables within the IIFE idiom and prevents it from polluting the global scope.

The second part of IIFE creates the immediately executing function expression, through which the JavaScript engine will directly interpret the function.

The syntax of an IIFE is as follows:

(function () {

What do you know about the different types of Popup boxes present in JavaScript?

You will find 3 types of Popup boxes available in JavaScript:


When should one use Arrow functions in ES6?

The thumb rule for functions in ES6 and beyond is as follows:

a) Use functions in the global scope and for Object.prototype properties.
b) Use class for object constructors.
c) Use => everywhere else.

What is the output in the console when the user clicks on “Button 4” and why?

No matter what button the user clicks, the output will always be 5. This is because when the onclick event invokes (when the user clicks any of the buttons), the ‘for’ loop is already finished and the value of the variable i is set to 5. All this happens at the time the document loads; the onclick event occurs later.

What is Typecasting in JavaScript?

In JavaScript, whenever we require to transform a variable from one data to another, then Typecasting is used. Besides, we can do this through library functions. There are mainly 3 typecasts that you will see in JavaScript Programming:

Boolean(value): Casts the inputted value to a Boolean
Number(value): Casts the inputted value to a Floating point Number or an Integer.
String(value) : Casts the inputted value value a string

Explain the function “use strict”.

“Use Strict” is a JavaScript directive that was launched in Es5. The main purpose of using this directive is to enforce the code is performed in strict mode. In this mode, we cannot use a variable without proclaiming it. This directive is ignored by the previous versions of JavaScript.

What is the JavaScript Event Delegation Model?

There is a lot of cool stuff available in JavaScript and one of them is Delegation model. When you are bubbling and capturing, it permit functions to apply a single handler to several elements at a specific time then it’s called Event Delegation. It basically permits you to put event listeners to single parent instead of particular nodes. That specific listener analyzes the bubbled events to get a match on the child elements. Several individuals think it to be daunting job but in reality, it seems easy if one begins to understand it.

Can you describe the main difference between a .forEach loop and a .map() loop and why you would pick one versus the other?

To understand the differences between the two, let’s look at what each function does.


Iterates through the elements in an array.
Executes a callback for each element.
Does not return a value.

const a = [1, 2, 3];
const doubled = a.forEach((num, index) => {
// Do something with num and/or index.

// doubled = undefined


Iterates through the elements in an array.
“Maps” each element to a new element by calling the function on each element, creating a new array as a result.
const a = [1, 2, 3];
const doubled = => {
return num * 2;

// doubled = [2, 4, 6]

The main difference between .forEach and .map() is that .map() returns a new array. If you need the result, but do not wish to mutate the original array, .map() is the clear choice. If you simply need to iterate over an array, forEach is a fine choice.

How set object is used in JavaScript?

Set objects are used to store different values to the elements. The values may be a reference or primitive values.

function display()
var set = new Set();
set.add( "Angular JS":;
set.add(" Vue");
set.add("React JS);
for(set the elements of set)

Write about number objects?

Number objects help to represent the number of values to the variables. The values may be floating-point or integer. In JavaScript, the floating points are represented by using the IEEE standard.

function display()
var a = 10;
var b = 0.7;
var c = 11d5;
doc.write(a+" "+b+" "+c+");

What will be the output of the following code?

var Employee =
company: 'xyz'
var Emp1 = Object.create(employee);
delete Console.log(;

The output would be xyz. Here, emp1 object has company as its prototype property. The delete operator doesn’t delete prototype property. emp1 object doesn’t have company as its own property. However, we can delete the company property directly from the Employee object using delete

What is the use of a Weakmap object in JavaScript?

Weakmap is similar to a collection of objects like a map. If the weak map object is set to a process, it considers each element as a key object and that key object will have a weak reference.

function display()
var wm = new WeakMap();
var object1 = {};
var object2 = {};
var object3 = {};
wm.set(object1, "AngularJS");
wm.set(object2, "ReactJS");
wm.set(object3, "VueJS");

Explain about MUL function in JavaScript?

MUL is a multiplication function. The multiplication of numbers can be done as a value is defined in the function and the value is returned by another function and the process goes on.

function mul(a)
return function(b)
return function(c)
return a*b*c;

When should we use generators in ES6?

To put it simple, generator has two features:

one can choose to jump out of a function and let outer code to determine when to jump back into the function.
the control of asynchronous call can be done outside of your code

The most important feature in generators — we can get the next value in only when we really need it, not all the values at once. And in some situations it can be very convenient.

What is generator in JS?

Generators are functions which can be exited and later re-entered. Their context (variable bindings) will be saved across re-entrances. Generator functions are written using the function* syntax. When called initially, generator functions do not execute any of their code, instead returning a type of iterator called a Generator. When a value is consumed by calling the generator's next method, the Generator function executes until it encounters the yield keyword.

The function can be called as many times as desired and returns a new Generator each time, however each Generator may only be iterated once.
function* makeRangeIterator(start = 0, end = Infinity, step = 1) {
let iterationCount = 0;
for (let i = start; i < end; i += step) {
yield i;
return iterationCount;

How do you remove duplicates from a JavaScript array?

There are two ways in which we can remove duplicates from a JavaScript array:
An empty array is used for storing all the repeating elements.

By Using the Filter Method
To call the filter() method, three arguments are required. These are namely array, current element, and index of the current element.
By Using the For Loop

Why is it common to wrap the content of JavaScript source file in a function book?

Many JavaScript libraries use this technique. It helps to develop a closure around the contents of the file which helps to create a private namespace and hence, avoid any name clash with different JavaScript modules and libraries.

What output will this code present:

//nfe (named function expression)

var Foo = Function Bar()


return 7;


typeof Bar();

Output = Reference Error. The function definition can only have one reference variable as the function name.

State the difference between Apply and Call?

The call() method helps to call a function which has a given ‘this’ value and the arguments which are individually provided. The syntax is:[, arg1[, arg2[, …]]])

The apply() method is used to call a function which has a given ‘this’ value but the arguments are presented as an array. The syntax is:

fun.apply(thisArg, [argsArray])

In JavaScript, what is the use of the prompt box?

The prompt box in JavaScript helps the user to input with the help of a text box. The prompt() method helps to display the dialog box which prompts the visitor to provide an input.

In JavaScript, what will be the result of the problem: 2+5+“3”?

Since 2 and 5 are integers, normal addition will be executed. 3 however is a string and hence, there will be concatenation. “” represents a string.

How to convert string of any base to an integer using JavaScript?

By using the parseInt() function, you can transform numbers among different bases.

How are the JavaScript window and JavaScript document different from one another?

Window is a global object and it holds functions, variables, location and history.

Document is a part of the window and is deemed as a property of the Javascript window.

How is Local Storage different from Session Storage?

Local Storage – In local storage, the data will not be returned to the server at every HTTP request (images, HTML, CSS, JavaScript, etc). It helps to reduce the traffic between server and client.

Session Storage – Session Storage is quite similar to the local storage. However, unlike data storage in local systems which has an expiry time, data stored using session storage gets cleared once the page session ends.

What is typed language?

In Typed Language, values are associated with values alone. They are not associated with variables. There are two types of Typed Language:

Dynamically: For Dynamically Typed language, the variable can hold several types.

Statically: In Statically Typed languages, the variable is capable of holding only one type.

Can you write a JavaScript code for adding new elements in a dynamic manner?

<script type="text/javascript">

function addNode() {

var newP = document.createElement("p");

var textNode = document.createTextNode(" This is a new text node");

newP.appendChild(textNode); document.getElementById("firstP").appendChild(newP);



What is the Strict mode in JavaScript?

Strict mode in JavaScript introduces more stringent error-checking in a JavaScript code.

a) While in Strict mode, all variables have to be declared explicitly, values cannot be assigned to a read-only property, etc.

b) We can enable strict mode by adding ‘use strict’ at the beginning of a JavaScript code, or within a certain segment of code.

What’s the difference between let and var?

Both let and var are used for variable and method declarations in JavaScript. So there isn’t much of a difference between these two besides that while var keyword is scoped by function, the let keyword is scoped by a block.

What are the ways of adding JavaScript code in an HTML file?

There are primarily two ways of embedding JavaScript code:

We can write JavaScript code within the script tag in the same HTML file; this is suitable when we need just a few lines of scripting within a web page.

We can import a JavaScript source file into an HTML document; this adds all scripting capabilities to a web page without cluttering the code.

What is the ‘this’ keyword in JavaScript?

The ‘this’ keyword in JavaScript refers to the currently calling object. It is commonly used in constructors to assign values to object properties.

What are the advantages of JavaScript over other web technologies?

These are the advantages of JavaScript:

Enhanced Interaction

JavaScript adds interaction to otherwise static web pages and makes them react to users’ inputs.

a) Quick Feedback

There is no need for a web page to reload when running JavaScript. For example, form input validation.

b) Rich User Interface
JavaScript helps in making the UI of web applications look and feel much better.
c) Frameworks
JavaScript has countless frameworks and libraries that are extensively used for developing web applications and games of all kinds.

What are the various data types that exist in JavaScript?

These are the different types of data that JavaScript supports:

Boolean - For true and false values
Null - For empty or unknown values
Undefined - For variables that are only declared and not defined or initialized
Number - For integer and floating-point numbers
String - For characters and alphanumeric values
Object - For collections or complex values
Symbols - For unique identifiers for objects

What do you understand about JavaScript?

JavaScript is a popular web scripting language and is used for client-side and server-side development. The JavaScript code can be inserted into HTML pages that can be understood and executed by web browsers while also supporting object-oriented programming abilities.

R4R Team
R4R provides JavaScript Freshers questions and answers (JavaScript Interview Questions and Answers) .The questions on website is done by expert team! Mock Tests and Practice Papers for prepare yourself.. Mock Tests, Practice Papers,Javascript interview question set 2,JavaScript Freshers & Experienced Interview Questions and Answers,JavaScript Objetive choice questions and answers,JavaScript Multiple choice questions and answers,JavaScript objective, JavaScript questions , JavaScript answers,JavaScript MCQs questions and answers Java, C ,C++, ASP, C# ,Struts ,Questions & Answer, Struts2, Ajax, Hibernate, Swing ,JSP , Servlet, J2EE ,Core Java ,Stping, VC++, HTML, DHTML, JAVASCRIPT, VB ,CSS, interview ,questions, and answers, for,experienced, and fresher R4r provides Python,General knowledge(GK),Computer,PHP,SQL,Java,JSP,Android,CSS,Hibernate,Servlets,Spring etc Interview tips for Freshers and Experienced for JavaScript fresher interview questions ,JavaScript Experienced interview questions,JavaScript fresher interview questions and answers ,JavaScript Experienced interview questions and answers,tricky JavaScript queries for interview pdf,complex JavaScript for practice with answers,JavaScript for practice with answers You can search job and get offer latters by studing .learn in easy ways .