JavaScript Interview Questions

By | April 24, 2019

Web-Development is one of the major opportunities for a computer science student. When we talk about front-end development it more about JavaScript. If you are looking forward your career as a front-end Web Developer you must have to face some interviews and, in the interview, you have to tackle questions more related to JavaScript so here we have some JavaScript questions from which you can prepare for the interview so you do not feel offhanded.

What is JavaScript?

JavaScript is a programming language; more specific it is client as well as a server-side scripting language. By scripting language, we mean that it can be embedded on HTML pages. It considers as programming language because it follows the concept of Object based programming language.

JavaScript Interview Questions

Question: Name the tech company which develops JavaScript?
Answer: Netscape

Question: Is JavaScript is related to Java?
Answer: No, JavaScript has nothing to do with Java both are used for different purposes though somehow both of them intersect when it’s come to front end development frameworks but apart from this both serve different purposes. Java is a General-purpose programming language whereas JavaScript is all about front end web development.

Question: Give some Difference between Java and JavaScript?

  • Java used for a general purpose which code runs on a virtual machine whereas JavaScript code runs on the web browser.
  • Java is an Object-oriented Programming language whereas JavaScript is an object-oriented scripting Language
  • We need to compile the code Java to run the programme whereas JavaScript code are all in text

Question: Name some of the main Features of JavaScript?

  • JavaScript is very lightweight
  • It interprets the code to execute it.
  • It can create a network-centric application
  • It is an open source
  • It is used to create a cross-platform hybrid application

Question: Name all the Data Types in JavaScript

  • Boolean
  • Number
  • Object
  • String
  • Undefined

Question: What does isNaN function do in JavaScript
Answer: isNaN is a built-in function of JavaScript which is used to check whether the passed argument is a number or not. If the argument is a number it returns True else it returns False.

Question: Is JavaScript Case-sensitive?
Answer: Yes, JavaScript is case-sensitive

Question: Is JavaScript faster than ASP script if yes, why?
Answer: Yes, JavaScript is Faster as compared to ASP script because JavaScript is a client-side language too which make it faster unlike ASP script which is Just a server-side language, it does not need any extra accessories such as compiler or interpreter to run its ode it can directly run on the user browser.

Question: Give Some advantages of Using JavaScript.

  • JavaScript always execute on the client environment which makes execution faster
  • It provides a rich User interface Interactivity
  • It is a very easy language to learn and the outputs are more satisfactory as compared to other programming language console black and white outputs.
  • Every Browser support JavaScript so you do not need any heavy IDE to write JavaScript code you can use your Notepad

Question: Comment on the negative infinity in JavaScript.
Answer: In JavaScript, if we divide a negative number with zero then it is termed as negative infinity.

Question: How do we perform break a string statement in JavaScript?

Answer: In JavaScript, we use backslash ‘\’ at the end of the line to break a string statement.

For example:

document.write(" Hello  \ world");

Question: What are the undefined variables in JavaScript?
Answer: In the programme, if we declare a variable and do not assign any value to it then the variable will be known as an undefined variable, but we try to access them to return something they return an undefined datatype.

Question: What are the undeclared variables?
Answer: The undeclared variable situation occurs when we got an error during the runtime this is because of those statements in which we try to access that variables which we had not declared.

Question: Create an object in JavaScript.
Answer: Though JavaScript supports the concept of an object, here how you can create an object in JavaScript.

var stu = {
name: "Sahil",
age: 16

Question: What are name functions in JavaScript?
Answer: In JavaScript when we declare a function, we give a name to it so we can call it whenever we want, the name is given to that function is known as name function, and to declare a function we use the function keyword.

function rank () { return "Captain"; }

Question: What are Global Variables in JavaScript?
Answer: In JavaScript, if we define a variable outside the function, which can be accessed by any function throughout the programme then it is known as Global variable.

If a global variable and local variable share the same name use window object to access a global variable

For example:

var myVar = "global_variable";   // Declare a global variable
function writeglobal() {


window.myVar = "global_variable";   // Declare a global variable
function writeglobal( ) {

Question: What is the Prompt box in JavaScript?
Answer: A prompt box in JavaScript is used to get input from the user, it provides a box in which the user can pass the inputs and the input could be a number or Text.

For example:


Question: What are timer functions in JavaScript name some of them?
Answer: In JavaScript, there are some built-in functions which are used to set a time period to execute some code. The functions come under timer functions are setTimeout, setInterval and clearinterval.

Question: What are comments in JavaScript and which symbols we use to comment something?
Answer: In JavaScript, if we comment a line it’s mean that it is not going to execute, we use comments to give some additional information about what the particular code is supposed to do.

We use // to comment a single line

And /* to comment out multiple lines */

Question: What are argument objects in JavaScript?
Answer: The argument which is passed along the function is known as a variable argument and it could be of any data type.

Question: What type of operator does in JavaScript?
Answer: The typeof operator returns the data type of variable which is passed along it.

For example:

var x= 20;
console.log(typeof x);

Question: What ‘this’ operator does in JavaScript?
Answer: ‘this’ is use an object which tells the functions to execute the current values of JavaScript code. In simple words, it is used to refer the current variable to the function.

Question: What does === operator do in JavaScript?
Answer: It is also known as identity operator it checks whether the values are equal and have the same data types if yes it returns true or else it returns false.

Question: What is the callback function in JavaScript?
Answer: In JavaScript, functions are objects that the reasons we can pass a function as an argument to another function and that function that is passed as an argument is called the callback function.

Question: Give the difference between ViewState and SessionState.
Answer: In ViewState when another page has loaded the data of the previous page lost.

In Session state data remain available until the user close the browser or the session ends.

Question: Does JavaScript automatically convert the type of data?
Answer: Yes, it does, it is also known as implicit type conversion.

Question: What are the rules for naming a variable in JavaScript?
Answer: When we name a variable, we should keep these points in our mind.

  • Do not use a reserved keyword as a variable name.
  • Do not start the variable name with digits (0-9) always use alphabets or underscore to start a variable name.
  • Variable names are case sensitive that means the car is not Car so always use lowercase as a variable name.

Question: Name all the loops of JavaScript.
Answer: JavaScript has 3 flow controls for loop

  • For loop
  • While loop
  • Do-while loop

Question: What are cookies in JavaScript?
Answer: When a user visits a website so some of the test files stores in the user system or browser those small test files are known as cookies.

Question: Create cookie using JavaScript
Answer: We use document.cookie object to create a cookie.


document.cookie = "key1 = value1; key2 = value2; expires = date";

Question: Name the ways by which we can read a write file in JavaScript.

  • By using the JS extension
  • Or by using the webpage and Active X objects

Question: What is Variable Typing in JavaScript?
Answer: The type of a variable is only known when it is defined, in JavaScript the type and value of the variable can be changed if the variable appears in a different context.


n = '1000000'        // Set 'n' as a string
n = 10000*100;     // n changed from string to number

Question: What typed language JavaScript is?
Answer: JavaScript is a Dynamically typed language because its variable can hold multi-types value.

For e.g.

In the previous question, we changed the type of n from a string to a number it means that n is not strict to only one type.

Question: How session storage is different from local storage.
Answer: Sessional storage is similar to the local storage but the difference is the data stored in the sessional storage does not available when the session ends or browser closed but the local storage is always there until it gets cleared manually.

Question: Is ‘==’ operator similar to ‘===’ operator?
Answer: == (equal operator) operator is used to check whether both operands having the same value or not, while ‘===’ checks whether both operands having the same value and type too or not.

Both the operators return Boolean values True and false based on the conditions

Question: Are null and undefined same?
Answer: No, both are different we call a variable undefined if we have not assigned any value to it but null itself a value. So, if a variable is null it means it is a defined variable.

Question: Name some Famous frameworks of JavaScript.
Answer: Here are some famous JavaScript Frameworks.

  • Angular
  • React
  • Vue

Question: What will happen if we use + operand between two strings?
Answer: It will concatenate both the string.

Question: What does delete operator do in JavaScript?
Answer: delete is a reserved keyword in JavaScript which is used to delete the property and value of any object.

Question: Name all the type of pop up boxes in JavaScript?
Answer: JavaScript has 3 boxes

  • Alert box
  • Confirmation box
  • Prompt box

Question: How the alert box is different from the confirmation box?
Answer: Alert box has only one button whereas confirmation box has two buttons.

Question: What does the pop() method does in JavaScript?
Answer: the pop() method usually operate on arrays it pop out or remove the last element of the array and returns it.

Question: Name the exception handling keyword used in JavaScript?
Answer: try, catch and finally. If the block of try executes failed due to some exception than the block of catch will execute. The finally block of code in either way whether there is an exception or not.

Question: When we use .call() and .apply() methods?
Answer: .call() method used when we the numbers of the argument are known and .apply() method used when the number of arguments is unknown.

Question: If arr is an array having 10 elements what happen if we write arr.length = 0?
Answer: The arr.length = 0 will remove all the elements of array arr and it will become an empty list. 

Leave a Reply

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