JavaScript is one of the essential dynamic programming languages used to provide dynamic interactivity on any website. It is typically used for frontend work such as markup and styling.

Are JavaScript developers in demand? Yes, today JavaScript is one of the most in-demand skills in the programming industry. According to the reports, 48% of employers worldwide say they need JavaScript skills. 

So, if you want to become a JavaScript professional, you can expect to get great opportunities and can get a higher salary. For entering in the world of JavaScript, this JavaScript interview questions guide along with accurate answers, will help you fetch a perfect job.

For Whom This JavaScript Question Answer Guide is Helpful?

This question and answer catalog is thoroughly prepared by examining the frequently asked JavaScript interview questions in multiple organizations. Anybody who is interested in JavaScript or is looking for a job requiring JavaScript programming language expertise will find this guide helpful. Some profiles are mentioned below:

  • JavaScript Developer (fresher & experienced both)
  • Front End Developer
  • User Interface Developer
  • React Native Developer
  • Ruby on Rails Developer
  • Web Developer

The JavaScript Interview question with an answer study guide is divided into four parts:

Top JavaScript Questions Asked by Interviewers-

Q1. What are the major advantages of JavaScript?

Ans. JavaScript is a programing language used for the web. It can alter the HTML content, attribute values, and CSS style. It can also Show/Hide HTML elements. Some of the other advantages of JavaScript are:

Advantages Description
Speed Excellent speed as it immediately runs within the client-side browser.
Interoperability Sound functionality with other programming languages. Easily embedded into any web page.
Third-Party Add-ons Known for its extended functionality. It supports third-party add-ons to build JavaScript applications.
Rich-Interface Used to include items like a drag, drop and sliders to present a rich interface to users/visitors.
Web Presence JS has a popular web presence. StackOverflow and GitHub extensively use JavaScript.
Versatile Capable of both Front-end (NodeJS) and Back-end development (Angular JS, React JS)

Q2. How can you differentiate JavaScript from Java?

Ans. Difference between JavaScript and Java are:

Difference Java JavaScript
Language Object-Oriented Programming Language Object-Oriented Scripting Language
Platform Runs in JVM Runs on a Web Browser
Compilation Programs are compiled and Interpreted Only integrated
Support Supported by maximum operating systems Supported by web browser with different OS
Scope Uses block-based scoping Uses function-based scoping

Q3. How to create an object in JavaScript?

Ans. Objects are the building blocks of modern JavaScript and are more of a reference data type.

Object Creating Ways Code
Object() var d = new object();
Object.create () Var a = Object.create(null);
Function Constructor var Obj = function(name) { = name


var c = new Obj(“Hi”);

Q4. What is the method to change the title of a page using JavaScript?

Ans. Generally, the page title varies based on the HTML document and the element structure. We can give id to an element and use code:



Q5. Tell some of the widely used JavaScript testing frameworks.

Ans. Some of the widely used JS Frameworks in 2019 are –

  • AngularJS – It is majorly used for developing SPA (single page applications. This framework is operated by Google and is fundamentally used for combining JS with HTML & CSS.
  • ReactJS – It is maintained by Facebook to build complex and interactive UI. For every DOM object, ReactJS has a “virtual DOM object”. ReactJS gives coder higher flexibility, and it makes use of JSX, render subcomponents.
  • JQuery – JQuery provides unique coding experience and is one of the oldest JavaScript frameworks preferred by big-shot names like Facebook, Google, and IBM.
  • NodeJS – NodeJS, an open-source server-side platform, is one of the most downloaded and widely used frameworks used for executing JavaScript coding.

Q6. Define some of the most prevalent JavaScript operators.

Ans. In JavaScript, operators are the symbols that help in performing different operations on the given data.

  • Arithmetic operators (+, -, *, /, %, ++, –)
  • Comparison operators (==, ===, !=, <,>, >=,<=)
  • Assignment operators (=, +=, -=, *=)
  • Logical operators – for

var a=10, b=20;

(a !=b) && (a<b); // RETURNS TRUE

Q7. JavaScript Functions – What do you know about it?

Ans. Something that performs a task to produce meaningful outputs is called function. JavaScripts also work on the concepts of both in-built JavaScript functions as well as user-defined functions.

Some of the common JavaScript Functions rules are:

  • It should begin by the keyword function
  • User-defined functions must have a unique name

Q8. What are some of the JavaScript data types?

Ans. Generally, there are 7 data types in JavaScripts:

  • Number let n =789;
  • String let str = “Hello”;
  • Boolean (‘True’ and ‘False’)
  • Null let gender = null;
  • Undefined (for unassigned values)
  • Objects and Symbols (for complex data structures)
  • Typeof operator (returns type of argument)

Q9. Describe different types of errors present in JavaScript.

Ans. In JavaScript, there are three different types of errors in programming.

  • Parsing errors – Also called Syntax errors, these errors occur at interpret time in JavaScript. It only affects the tread in which this error occurs, leaving other threads unaffected.
  • Run-time errors – Errors that appear at the time of execution and are also defined as exceptions.
  • Logical errors – These are one of the most difficult types of errors and occur whenever there are flaws in logics that drive the script. Catching these errors is a very difficult task.


Q10. Can you redirect a page to another page using JavaScript? How?

Ans. Yes, it is possible to redirect a page to another page or URL using JavaScript by using location, replace, and location.assign.

JavaScript Interview Questions and Answers for Beginner Level

From here begins the practice journey of your interview. You must go through all levels of questions and analyze the answers for preparing the forthcoming JavaScript interview.

It is also advisable to take the best JavaScript courses, certification, and training to intensify your JavaScript learning.

Q11. Define JavaScript and mention some of its features.

Ans. Initially known as LiveScript, JavaScript is almost two decades old dynamic programming language used for web pages allowing client-side interaction.

Some Exceptional JavaScript features are-

  • Highly useful while using forms
  • Platform independent
  • Unique built-in features for handling date and time
  • Includes rich interfaces like drag and drop

Q12. State the major difference between a programming language and a scripting language. Also tell, JavaScript is which form of language?

Ans. Programming languages are designed to take full usage of any language, and at the same time, scripting languages are designed to fast-pace the coding.

JavaScript is a scripting language. Some of the major differences between both the languages are-

Scripting Language Programming Language
Uses Interpreter Uses Compiler
Supports Script Consists of instructions for a computer
Combines existing components Develops from Scratch
Needs another program to run Runs independently

Also, Read>>5 Latest Web Development Tools that you must know!

Q13. What is the difference between Primitives and Objects in JS?

Ans. In JavaScript, values are of two types – Primitives and Objects. Some common differences between both are:

Objects Primitives
Mutable at the time of coding Immutable
Have a unique identity No individual identity
Compared by reference Compared by Value

Q14. What do you understand by the prompt() method?

Ans. Whenever you want to display a dialog with an optional message that prompts the user to input some text, the prompt() method is used. All major browsers including Google Chrome, Internet Explorer, and Firefox., support this

Q15. In JavaScript, what is ‘This’ keyword?

Ans. In JavaScript, the keyword ‘this’ refers to the object it belongs to and gives different values depending upon its usage.

For Example:

  • In method – refers own object
  • Alone – refers to the global object
  • Function – undefined (in strict mode)

Also, Read>>Create Your Own Mobile Application in 5 Simple Steps!

Q16. What are the types of JavaScript Function Scope?

Ans. Basically, the scope circumscribes the variable’s visibility. Talking about JavaScript, functions are first-class objects holding properties like an object. The only difference is that these functions can be called, unlike other objects. JavaScript covers majorly two types of Function Scope:

  • Local Scope – Variables defined inside the functions are called local to the function.
  • Global Scope – Outside area of all functions is considered global.

Q17. Give the difference between JavaScript keywords – var and let.

Ans. In JavaScript, var and let are used for variable deceleration, but var is known as function scope whereas, let is known as block scoped.

Q18. What you mean by Hoisting in JS?

Ans. The concept of hoisting stands for uplifting the variable and functions on the top of their scope before the code execution takes place. In the JavaScript mechanism, no matter wherever the functions are declared, they are taken on the topmost position, immaterial of their scope (global or local).

Q19. Name a few built-in methods.

Ans. JavaScript has several built-in methods which are classified as:

  • Number Methods – constructor(), toExponential(), toFixed()
  • Boolean Methods – toSource(), toString(), valueOf()
  • Date Methods – Date(), getFullYear(), getHours()
  • Math Methods – abs(), exp(), log()

Q20. How can you submit a form using JS?

Ans. To submit a simple form, the below code will work.


Q21. What do you mean by control flow and error handling in JS?

Ans. In JavaScript, control flow stands for a process that ensures that an appropriate order is followed to execute statements in a script. It also ensures that one must read not only the entire code but also check the program structure and how that structure affects execution.

Whereas, error handling in JS means catching an error using “try..catch” Initially, the code try functions in a way that if the code is error-free, catch function will be ignored. But in case any error is found, try execution is paused, and control(err) begins.

Q22. What is DOM in JS?

Ans. DOM stands for Document Object Modeling, which is language allowing dynamic accessing and modifying the content in any document. Level of abstractions DOM has in JavaScript:

  • DOM Level 1
  • DOM Level 2
  • DOM Level 3
  • Scalable Vector Graphics
  • Mathematical Mark-up Language

Q23. What is BOM in JS?

Ans. BOM stands for Browser Object Model, a more extensive representation of elements provided by the browser like document, location, history, and frames exposed to JavaScript. DOM is a part of BOM, and to access the document, one can use code document or window.document.

Q24. What is a JavaScript string?

Ans. Whenever we want to store or manipulate text, we use JavaScript strings. We need JavaScript String methods to work with strings.

Q25. In JavaScript, what does an Anonymous function do?

Ans. The function that has no defined name is called an anonymous function in JavaScript. One can easily use this function by replacing expression. This anonymous function can also be assigned to a variable. Further, this function can also be moved as an argument to a different function.

Q26. In JavaScript, how can you validate null or empty value?

Ans. It is essential to check the condition that any user has added any value in the given field. The below code will help:

// If the length is 0 then imitate helper message

function required(inputtx)


if (inputtx.value.length == 0)



return false;


return true;


Q27. Please list some of the Design Patterns in JS.

Ans. Whenever somebody wants to reuse solutions for regularly occurring problems in software designing, Design Patterns will solve the purpose.

Latest Design Patterns in JS are:

  • Module Design pattern
  • Revealing Module pattern
  • Prototype Design pattern
  • Revealing Prototype pattern
  • Observer Design pattern
  • Singleton

Also, Read>>Top Online Programming Courses.

Q28. Define the usage of Set object in JS.

Ans. Set objects in JavaScript are the source to store elements having unique values, including both primitive as well as the object reference values.

Q29. Deep vs. shallow object copying in JavaScript.


  • Deep Coping – This means that all the values of the existing/original variables are copied to a new variable, and thus, disconnected from the existing variables.
  • Shallow Coping – When commanded for shallow coping, not all the existing variables are disconnected, and some of the values or sub-values are still connected to the original.

JavaScript Interview questions for Intermediate Level

You have covered all the basic JavaScript interview questions, and now it’s time to move on to the next level. Aspirants appearing for intermediate JavaScript interviews can go through the below-detailed interview guide after clearing their JavaScript basic version of questions.

Q30. How to formulate a cookie using JS?

Ans. A cookie is a set of data saved on the computer and accessed by the browser.

Step to create a JavaScript cookie :

document.cookie = “cookiename=John”; expires = date”;

Q31. Once a cookie is created, how to read a cookie using JS?

Ans. In the case of JavaScript, cookies can be read as:

Var x = document.cookie;

Q32. In HTML, how many ways are there to involve JS?

Ans. For this javascript interview question, your reply should be –

There are three ways to include JavaScript in HTML:

  • Sandwich the JavaScript code by defining a pair <script></script> tags of HTML
  • Create an external JavaScript file to define <script src=”Script.js”></script> in HTML
  • Directly code the JavaScript into HTML element

Q33.Differentiate Cookies, LocalStorage, and sessionStorage.

Ans. Cookies – Cookies are those small sets of data, consisting of a name and value, stored by a web browser. JavaScript facilitates cookie creation, retrieval, and deletion via an intuitive interface.

LocalStorage – A unique type of web storage, which allowsJS websites to store and obtain data in the browser without any specified expiry date.

SessionStorage- Saves data only for one session, and as soon as the tab is closed, its deleted.

Features Cookies localStorage sessionStorage
Data Size 4 KB 5 MB 5 MB
Blockable Yes Yes Yes
Auto-expiration Yes No Yes
Data Transferred on HTTP request Yes No No

Q34.What is the major difference between == and === operators?

Ans. It is one of the favorite javaScript interview questions asked by an interviewer for the profile of web developers.

The major difference between == Operator and === Operator is that === considers type of variables whereas == makes corrections based on the values of variables. === is strictly an equality operator.

Q35.Define isNaN in JS.

Ans. isNaN is a function used for defining a function true if in case the argument is not a number.

Q36.How to remove the focus from a specified object in JS?

Ans. Blur function can be highly useful in removing the focus.

Q37.How to enable Strict mode in JS?

Ans. In JavaScript programming language, when strict mode is enabled, it adds compulsions. This function is used for solving some of the mistakes hindering the efficiency of the JavaScript engines. The code is:

functions myfunction()


“use strict”,

var v = “ Strict Mode Enabled”;


Q38.What is event bubbling in terms of JS?

Ans. Event bubbling, as well as event capturing, is one of the widely used terminologies in JS, and that is why interviewers compulsorily ask the meaning of this jargon.

In JS, Event Flow process is evolved by three concepts:

  • Event capturing
  • Event Target
  • Event Bubbling

The event starting from the target element to its parent element and further-reaching its ancestors is called event bubbling. Generally, all the browsers have event bubbling as their default flow of the event.

Q39.If you want to move an element in lowercase to uppercase from an array, what will you do?

Ans. Use the method – toUpperCase to return the string value to uppercase.

Q40.If you need to calculate the Fibonacci series in JS, what will you do?

Ans. Fibonacci series is a pattern in which each given value is the sum of the previous two, and it starts with 0,1.


  • use function fib(n),
  • Declare var a=0 and b=1
  • Use this condition (var i=0; i<n; i++)
  • Use var temp = a+b;
  • Next make a=b
  • And b=temp;
  • }
  • Return a;

The series will come like 0,1,1,2,3,5…

Q41.Define the output for *2 in JS.

Ans. NaN will be the output as *2 is undefined.

Q42.What are screen objects and their properties?

Ans. Objects used to read the information available on the client’s screen are called screen objects. Some of the properties are:

  • AvailHeight
  • AvailWidth
  • ColorDepth

Advanced Level JavaScript Interview Questions

You have covered almost all the basic and intermediate JavaScript interview questions, and now it’s time to practice some of the difficult levels of questions for your upcoming job interview.

Q43.Highlight the major difference between Call & Apply.

Ans. call() method refers to a method that takes the owner object as an argument. To use a method on different objects, we use the call method.

Parameters that a call function considers:

  • objectInstance – holding the instance of the object
  • arguments: considers comma as a separate argument

apply method is something that helps in writing the method to be used on separate objects.

Parameter of a method function:

  • objectInstance – holds an instance of an object
  • arrayOfArguments – call method considers an array of arguments

So the major difference between the two functions is that unlike the call function, the ‘method’ uses an array of arguments.

Q44.In JavaScript, append a new element at the end of the array.

Ans. To append an element in a JavaScript array, we use push(), and to remove an array, pop() is used.


array.push(item1, item2, …, itemX)

Q45.Empty an Array in JS.

Ans. Several ways to empty an array:

  • arrayList = []
  • length = 0;
  • while(arrayList.length)




Q46.What will the statement declare?

var myArray = [[[]]];

Ans. It will declare that its a three-dimensional array.

Q47.Define Escape character in JavaScript.

Ans. If you want to write some special character without overlapping the application, the escape character will do the task. The backslash character (the escape characters) is used for employing special characters (‘’, “”, ‘, &)

Example: document. write “I am a “healthy” girl”

Q48.Why popular JS libraries wrap the entire content of the JS source file in a function book?

Ans. Generally, there are two popular reasons for wrapping JavaScript libraries in a function book:

  • Avoid polluting the global scope
  • Avoid overriding existing variables

This practice is majorly used in jQuery plugins and is exercised by the most popular JavaScript libraries.

Q49.Give the output of the below code.

var Student =


college: ‘abc’


var Stud1 = Object.create(Student);

delete Console.log(;

Ans. The output will be abc


  • college is the Prototype property of Stud1
  • The operator that is used in code ‘delete’ doesn’t delete the prototype property
  • Stud1 don’t have college as its own property
  • To delete college property directly from the object Student use delete

Q50. Give the output of the below code:

var Output = (function(a)


Delete A;

return A;




Ans. The output will be 0.

As ‘A’ is a local variable and not an object, and delete operators leave local variables unaffected.

Q51. How do we add/remove properties to objects dynamically in JS?

Ans. We can add a property to an object by using:

object.property_name =value

To delete a property, we can use:



   let user = new Object();

    // adding a property’John’;

    user.age  =22;


    delete user.age;


Q52. How to get inner Html of an element in JS?

Ans. To get inner Html of an element in JavaScript, we can use InnerHTML property of HTML DOM.


This is inner Element

<script type=”text/javascript”>

var  inner= document.getElementById(“inner”).innerHTML ;

console.log(inner); // Inner Element

document.getElementById(“inner”).innerHTML = “Html changed!”;

var  inner= document.getElementById(“inner”).innerHTML ;

console.log(inner); // Html changed!


Q53. What is the procedure to remove duplicate values from a JSarray?

Ans. First, we can check whether a duplicate value exists or not by using array.indexOf method. Let’s see the given example to remove duplicate values.

let duplicates = [‘Spain’,’Russia’,’Russia’,’China’,’America’,’New Jersy’];

function removeDuplicatesValues(arr){

    let unique_array = [];

    for(let i = 0;i < arr.length; i++){

        if(unique_array.indexOf(arr[i]) == -1){




    return unique_array



Q54. What will be the output of the code?

var Employee = {

company: ‘CompanyNW’


var emp0 = Object.create(Employee);



Ans. The output of the given code would be CompanyNW. Where emp0 object has company as its prototype property. The delete operator will not delete prototype property.

Q55. How do we create blink text using JS?

Ans. Syntax:




     var str1 = “Upskill your Learning”;

     var response = str1.blink();





Q56. How can we read elements of an array?

Ans. Syntax:

var num1 = [0, 1, 2, 3, 4];

for (var i = 0; i < num1.length; i++) {



Q57. What is the possible way to give a comment?

Ans. Syntax:

Single line comment – // Single-line comments.

Multiple line comments – /* Multi Line Comment

Q58. Mention HTML DOM mouse events?

Ans. Following are the HTML DOM mouse events:

  • onclick
  • ondblclick
  • mouseout
  • mouseover
  • Mouseup
  • mousemove
  • mousedown

Q59. How do we get the primitive value of a string in?

Ans. In Javascript, we can use the valueOf() method to get the primitive value of a string.


var myVar= “Naukri”


Q60. How do we create an array?

Ans. Following are three different ways to create an array in Javascript:

  • By array literal
    var myArray=[value1,value2…valueN];
  • By creating instance of Array
    var myArray=new Array();
  • By using an Array constructor
    var myArray=new Array(‘value1′,’value2′,…,’valueN’);

Q61. What is the possible way to give default arguments in function?

Ans. Syntax:

function print(arr = [], direction = ‘A1`) {

  document.write(‘Array Printing’, arr, direction)


print([1, 2, 3, 5])

print([1, 2, 3], ‘A2’)

Q62. What is the procedure to merge two arrays?

Ans. Syntax:

var arr1 = [1,2,3]

var arr2 = [4,5,6,7]

var mergedArrays = […arr1, …arr2]

document.write(‘Merged arrays’, mergedArrays)

Q63. Explain the for-in loop?

Ans. The for-in loop is used to loop the object through properties.


for (variable name in object){

statement to execute


Q64. How do we target a particular frame from a hyperlink?

Ans.  We can target a particular frame from a hyperlink by consisting the name of the required frame and can use ‘target’ attribute in it.

<a href=”/newpage.htm” target=”newframe”>>New Page</a>

Q65. Name the method we can use to read and write a file in JavaScript?

Ans. JavaScript extensions can be used to read and write a file such as for opening of a file –

fh = fopen(getScriptPath(), 0);

Q66. Explain what are Screen objects?

Ans. Screen objects hold information from the client’s screen. It is also used to display screen width, pixelDepth, height, etc. Let’s look at the properties of screen objects-

  • AvailWidth: Provides the width of the client’s screen
  • AvailHeight: Provides the height of the client’s screen
  • ColorDepth: Provides the bit depth of images on the client’s screen
  • Width: Provides the total width of the client’s screen, including the taskbar
  • Height: Provides the total height of the client’s screen, including the taskbar

Q67. What does the below given statement explain?

Ans. var myArray = [[[]]];

It explains a three-dimensional array.

Q68. What syntax we can use to hide JavaScript codes from old browsers that don’t support JavaScript?

Ans. We can use given codes for hiding JavaScript codes from old browsers:

Use “<!–” without the quotes in the code after the <script> tag.

Use “//–>” without the quotes in the code before the <script> tag.

These codes are not treated by old browsers whereas a browser that supports Javascript, it will take the “<!–” and “//–>” as one-line comments.

Q69. Write the output of undefined * 2 in Javascript?

Ans. The output of undefined * 2 is “nan”. 

Q70. How we can add or remove properties to objects?

Ans. We can add a property to an object with the help of object.property_name =value and delete object.property_name is used to delete a property.


   let user = new Object();

    // add a property’John’;

    user.age  =21;


    delete user.age;


Q71. Explain “use strict” ?

Ans. In Javascript, “use strict” is used to enforce the code in strict mode where we can’t use any variable without declaring it. “use strict” was not considered by earlier versions of Javascript.

Q72. How do we convert Javascript date to ISO standard?

Ans. To convert Javascript date to ISO standard, we can use toISOString() method. It will convert a JavaScript Date object into a string, using the ISO standard.


var date = new Date();

var n = date.toISOString();


Q73. Can we do 301 redirects in Javascript ?

Ans. We cannot do 301 redirect in Javascript as it totally runs on the client machine. 301 is the response code that is sent by the server as a response. 

Q74. Explain what is a callback in JS?

Ans. A callback is used as a JavaScript function transferred to some method as argument or option. It can make events like if any state is matched then can trigger to some other function.

Q75. When we can use of JSON.stringify()?

Ans. We use this method to convert a JavaScript Json data to a string.

Key Takeaways-

These interview question series will help you to crack the interview.

In case you are looking for grooming your skills in the arena of JavaScript or looking for building interactive applications, you must undergo courses like the modern javascript bootcamp course. This course is well-equipped for web developers as it covers the fundamentals of Advanced JavaScript and HTML required to make user-friendly and robust websites.

We wish you all the success for your forthcoming interviews, and in case if you have appeared for one, post the questions asked by the interviewer in the comment section below. 

Download PDF


If you have recently completed a professional course/certification, click here to submit a review and get FREE certification highlighter worth Rs. 500.

5.00 avg. rating (97% score) - 2 votes