JavaScript Interview Questions

What is JavaScript?

JavaScript is a client-side and server-side scripting language inserted into HTML pages and is understood by web browsers. JavaScript is also an Object-based Programming language

Enumerate the differences between Java and JavaScript?

Java is a complete programming language. In contrast, JavaScript is a coded program that can be introduced to HTML pages. These two languages are not at all inter-dependent and are designed for different intent. Java is an object-oriented programming (OOPS) or structured programming languages like C++ or C, whereas JavaScript is a client-side scripting language.

What are JavaScript Data Types?

“Following are the JavaScript Data types:


JavaScript Interview Questions

What is the use of isNaN function?

isNan function returns true if the argument is not a number; otherwise, it is false.

Which is faster between JavaScript and an ASP script?

JavaScript is faster. JavaScript is a client-side language,, and thus it does not need the assistance of the webserver to execute. On the other hand, ASP is a server-side language and hence is always slower than JavaScript. Javascript now is also a server-side language (NodeJS).

What is negative Infinity?

Negative Infinity is a number in JavaScript which can be derived by dividing negative number by zero.

Advance JavaScript Interview Questions

Is it possible to break JavaScript Code into several lines?

“Breaking within a string statement can be done by using a backslash, ‘\,’ at the end of the first line.


document. Write (“”This is \a program,””);
And if you change to a new line when not within a string statement, then javaScript ignores the break in the line.


var x=1, y=2,
The above code is perfectly fine, though not advisable as it hampers debugging.”

Which company developed JavaScript?

Netscape is the software company that developed JavaScript.

What are undeclared and undefined variables?

“Undeclared variables are those that do not exist in a program and are not declared. If the program tries to read the value of an undeclared variable, then a runtime error is encountered.

Undefined variables are those that are declared in the program but have not been given any value. If the program tries to read the value of an undefined variable, an undefined value is returned.”

JavaScript Interview Questions

What is a prompt box?

A prompt box is a box that allows the user to enter input by providing a text box. A label and box will be provided to enter the text or number.

What is ‘this’ keyword in JavaScript?

‘This’ keyword refers to the object from where it was called.

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 set Timeout, set Interval, and clear Interval.

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

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

JavaScript Interview Questions

What is the difference between View State and Session State?

“View State’ is specific to a page in a session.
‘Session State’ is specific to user-specific data that can be accessed across all web application pages.”

What is === operator?

=== is called a strict equality operator, which returns true when the two operands have the same value without conversion.

How you can submit a form using JavaScript?

“To submit a form using JavaScript use


JavaScript Interview Questions

Does JavaScript support automatic type conversion?

Yes, JavaScript does support automatic type conversion. It is the common way of type conversion used by JavaScript developers

How can the style/class of an element be changed?

“It can be done in the following way:

document.getElementById(“”myText””). style. fontSize = “”20″”;

document. getElementById (“”myText””). className = “”anyclass””;”

How to read and write a file using JavaScript?

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

Using JavaScript extensions
Using a web page and Active X objects”

JavaScript Interview Questions

What are all the looping structures in JavaScript?

“Following are looping structures in Java script:

Do-while loops”

What is called Variable typing in Java script?

“Variable typing is used to assign a number to a variable. The same variable can be assigned to a string.


i = 10;
i = “”string;”””

How can you convert the string of any base to an integer in JavaScript?

“The parseInt () function is used to convert numbers between different bases. parseInt() takes the string to be converted as its first parameter. The second parameter is the base of the given string.

To convert 4F (or base 16) to integer, the code used will be –

parseInt (“”4F””, 16);”

Advance JavaScript Interview Questions

Difference between “==” and “===”?

“==” checks only for equality in value, whereas “===” is a stricter equality test and returns false if either the value or the type of the two variables are different.

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.

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.

JavaScript Interview Questions

What do you mean by NULL in Java script?

The NULL value is used to represent no value or no object. It implies no object or null string, no valid boolean value, no number, and no array object.

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;”

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.”

Advance JavaScript Interview Questions

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

Confirm and

What is the use of Void (0)?

“Void(0) is used to prevent the page from refreshing, and parameter “”zero”” is passed while calling.

Void(0) is used to call another method without refreshing the page.”

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.”

JavaScript Interview Questions

What are JavaScript Cookies?

Cookies are the small test files stored in a computer, and they get created when the user visits the websites to store information that they need. Examples could be User Name details and shopping cart information from previous visits.

Does JavaScript has concept level scope?

No. JavaScript does not have concept-level scope. The variable declared inside the function has scope inside the function.

What are the disadvantages of using inner HTML in JavaScript?

“If you use inner HTML in JavaScript, the disadvantage is

Content is replaced everywhere
We cannot use it like “”appending to inner HTML
Even if you use +=like “”inner HTML = inner HTML + ‘html'”” still the old content is replaced by html
The entire inner HTML content is re-parsed and builds into elements. Therefore, it’s much slower
The inner HTML does not provide validation, and therefore we can potentially insert valid and broken HTML in the document and break it”

Advance JavaScript Interview Questions

What is break and continue statements?

“Break statement exits from the current loop.

Continue statement continues with next statement of the loop.”

What are the two basic groups of data types in JavaScript?

“They are as—Primitive
Reference types
Primitive types are number and Boolean data types. Reference types are more complex types like strings and dates.”

What is the use of a type of operator?

‘Type of’ is an operator used to return a string description of the type of a variable.

JavaScript Interview Questions

Which keyword is used to print the text on the screen?

Document. Write (“Welcome”) is used to print the text–Welcome on the screen.

What is the use of the blur function?

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

How to find an operating system in the client machine using JavaScript?

The ‘Navigator. the app version is used to find the operating system’s name in the client machine.

Advance JavaScript Interview Questions

What are the different types of errors in JavaScript?

“There are three types of errors:

Load time errors: Errors that come up when loading a web page, like improper syntax errors, are known as Load time errors and generate the errors dynamically.
Runtime errors: Errors that come due to misuse of the command inside the HTML language.
Logical Errors: These are the errors that occur due to the bad logic performed on a function with a different operation.”

What is the use of the Push method in JavaScript?

The push method is used to add or append one or more elements to an Array end. Using this method, we can append multiple elements by passing multiple arguments.

What is the unshift method in JavaScript?

Unshift method is like the push method, which works at the beginning of the array. This method is used to prepend one or more elements to the beginning of the array.

JavaScript Interview Questions

What is the difference between JavaScript and Jscript?

Both are almost similar. Netscape and Jscript develop JavaScript was developed by Microsoft.

What is the ‘Strict Mode in JavaScript, and how can it be enabled?

“Strict Mode adds certain compulsions to JavaScript. Under the strict Mode, JavaScript shows errors for a piece of code, which did not show an error before, but might be problematic and potentially unsafe. Strict Mode also solves some mistakes that hamper the JavaScript engines from working efficiently.

Strict mode can be enabled by adding the string literal “”use strict”” above the file. This can be illustrated by the given example:

function my function() {
“”use strict;””
var v = “”This is a strict mode function””;

What is the way to get the status of a Checkbox?

“The status can be acquired as follows –

If the Checkbox is checked, this alert will return TRUE.”

Advance JavaScript Interview Questions

How can the OS of the client machine be detected?

The navigator. app Version string can be used to detect the operating system on the client machine.

What is a window. onload and on Document Ready?

“The onload function is not run until all the information on the page is loaded. This leads to a substantial delay before any code is executed.

on Document Ready loads the code just after the DOM is loaded. This allows early manipulation of the code.”

How closures work in JavaScript?

“The closure is a locally declared variable related to a function that stays in memory when it has returned.

For example:

function greet(message) {
function greeter(name, age) {

return name + "" says howdy!! He is "" + age + "" years old"";
// Generate the message
var message = greeter(""James"", 23);
// Pass it explicitly to greet
This function can be better represented by using closures
function greeter(name, age) {
var message = name + "" says howdy!! He is "" + age + "" years old"";
return function greet() {
// Generate the closure
var JamesGreeter = greeter(""James"", 23);
// Use the closure

JavaScript Interview Questions

How can a value be appended to an array?

“A value can be appended to an array in the given manner –

arr[arr.length] = value; “

What is for-in loop in Javascript?

“he for-in loop is used to loop through the properties of an object.

The syntax for the for-in loop is –

for (variable name in object){
statement or block to execute
In each repetition, one property from the object is associated with the variable name. The loop is continued till all the properties of the object are depleted.”

JavaScript Part 2JavaScript Part 3
Back to top