JavaScript Interview Questions and Answers

By | November 26, 2021
Javascript Interview Questions

Web-Development promises evergreen Job opportunities to its developers. When we talk about front-end development, it mostly about JavaScript. If you are looking forward to being a front-end Web Developer and want to land a job in any company, then you must have to face some interviews. Here in this article, we have covered the best JavaScript interview questions, which will help you to crack the interview.



JavaScript is one of the top 20 programming languages of 2020. It is a scripting language that primarily used for client-side software development, but with the release of Node.js, now it can be used at the server-side. Every webpage or application you see on the internet including JavaScript for the development of the better user interface. Big companies such as Facebook and Google are millions of dollars on JavaScript to build interactive, intuitive and responsive web-applications which could run on any device. 

JavaScript Interview Questions

1. What is JavaScript?

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

2. Name the tech company which develops JavaScript?

Answer: Netscape

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

4. Give some Differences between Java and JavaScript?


  • Java is used for a general-purpose in 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 program whereas JavaScript code is all in text.

5. What do you understand by ECMAScript?

Answer: ECMAScript (European Computer Manufacturers Association) is an association for scripting language standards. JavaScript is the best implementation of this association.

6. What is the latest version of JavaScript?

Answer: The latest version of JavaScript is ECMAScript 2021 (ES2021), released in June 2021. It is also known as the 12th edition of JavaScript.

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

8. Name all the Data Types in JavaScript


  • Boolean
  • Number
  • Object
  • String
  • Undefined

9. What does the 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.

10. Are Attributes and Properties in JavaScript are the same?

Answer: No, they both are different. Attributes can be defined as one which can give more details on elements like id, type, value etc. whereas, property are those values that are assigned to elements like type=”text”.

11. Is JavaScript Case-sensitive?

Answer: Yes, JavaScript is case-sensitive. Every keyword, function name, variable, or any other identifier is written in Java with a consistent capitalization of letters.

12. 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 a compiler or interpreter to run its ode it can directly run on the user browser.

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

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

15. How do we perform breaking a string statement in JavaScript?


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

For example:

document.write(" Hello  \ world");

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

17. 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 those variables that we had not declared.

18. Create an object in JavaScript.


Though JavaScript supports the concept of an object, here is how you can create an object in JavaScript.

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

19.: 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 the name function, and to declare a function we use the function keyword.

function rank () 
return "Captain"; 

20. 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 a 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( ) {

21. 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:


22 What are timer functions in JavaScript name some of them?

Answer: In JavaScript, there are some built-in functions that are used to set a time period to execute some code. The functions that come under timer functions are setTimeout, setInterval and clear interval.

23. What are comments in JavaScript and which symbols do we use to comment on something?

Answer: In JavaScript, if we comment on 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 on a single line

And /* to comment out multiple lines */

24. What are argument objects in JavaScript?


The argument which is passed along the function is known as a variable argument and it could be of any data type.

console.log(typeof x, arguments.length);
func(); //==> "undefined", 0
func(7); //==> "number", 7
func("1", "2", "3"); //==> "string", 3

25. What type of operator does JavaScript?

Answer: The type of operator returns the data type of variable which is passed along it.

For example:

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

26. What does ‘this’ operator does in JavaScript?

Answer: ‘this’ is using 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.

27. What does === operator do in JavaScript?

Answer: It is also known as an 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.

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

29. Give the difference between ViewState and SessionState.


In ViewState when another page has loaded the data of the previous page is lost.

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

30. Does JavaScript automatically convert the type of data?

Answer: Yes, it does, it is also known as implicit type conversion.

31. What are the rules for naming a variable in JavaScript?


When we name a variable, we should keep these points in our minds.

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

32. Name all the loops of JavaScript.


JavaScript has 3 flow controls for loop

  • For loop
  • While loop
  • Do-while loop

33. What are cookies in JavaScript?

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

34. Create cookie using JavaScript


We use document.cookie object to create a cookie.


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

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

36. How to change an element’s style or class in JavaScript?


document.getElementById("myText").style.fontSize = "20?;
document.getElementById("myText").className = "anyclass";

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

38. Automatic type conversion is possible in JavaScript or not?

Answer:  Yes, it is possible and it is the common way of type conversion used in JavaScript.

39. Which code is used to submit a form in JavaScript?

Answer:  document.form[0].submit();

40. What type of language JavaScript is?


JavaScript is a Dynamically typed language because its variable can hold multi-type values.

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.

41. How session storage is different from local storage.

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

42. JavaScript and JScript are the same or not?

Answer: No, they both are different. JavaScript is a product by Netscape and JScript is a product by Microsoft.

43. Is ‘==’ operator similar to ‘===’ operator?


== (equal operator) operator is used to check whether both operands have the same value or not, while ‘===’ checks whether both operands have the same value and type too or not.

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

44. Are null and undefined the 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.

45. What is the NULL in JavaScript?

Answer:  NULL means no value or no object.

46. Find the result of 6+3+”9”?


Here 6 and 3 are the integer values and 9 is a string so it will be concatenated with the result.

So the and is: 99

47. Name some Famous frameworks of JavaScript.


Here are some famous JavaScript Frameworks.

  • Angular
  • React
  • Vue

48. What will happen if we use + operand between two strings?

Answer: It will concatenate both the string.

49. What does the 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.

50. How to perform the delete operation in JavaScript?


By using the delete operator, the delete operation is performed in JavaScript.


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

51. Name all the types of pop up boxes in JavaScript?

Answer: JavaScript has 3 boxes

  • Alert box
  • Confirmation box
  • Prompt box

52. How the alert box is different from the confirmation box?

Answer: Alert box has only one button whereas the confirmation box has two buttons.

53. What does the pop() method does in JavaScript?

Answer: the pop() method usually operate on arrays it pops out or remove the last element of the array and returns it.

54. Name the exception handling keyword used in JavaScript?

Answer: try, catch and finally. If the block of try executes failed due to some exception then the block of catch will execute. The finally block of code in either way whether there is an exception or not.

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

55. When we use .call() and .apply() methods?

Answer: .call() method used when the numbers of the argument are known and .apply() method used when the number of arguments is unknown.

56. If arr is an array having 10 elements what happens 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. 

57. How to create an Array in JavaScript?

Answer: Defining the array:

var x = [];
var y = [1, 2, 3, 4, 5];

58. How many ways are there to involve a JavaScript code in the HTML file?

Ans: There are 3 ways to do this:

  • Inline
  • External
  • Internal

59. What are the Mouse Events?

Ans: There are 9 mouse events that can be performed in JavaScript:

  1. click,
  2. dblclick,
  3. mousedown,
  4. mouseup,
  5. mouseenter,
  6. mouseleave,
  7. mouseover,
  8. mouseout,
  9. mousemove

60. Write a script to reverse a string.


let string = "Welcome to TechGeekBuzz"; 
str_rev = string.split("").reverse().join("");

"zzuBkeeGhceT ot emocleW"

61. Mention the various techniques we can use to empty an array.


Suppose we have an array

let = array=[1,2,3,4,5,6,7,8,9,10]

Method 1: Reassigne an empty array to the variable array.

array = []

Method 2: Set the length of array =0

array.length = 0

Method 3: Use the splice method to set the array length 0

array.splice(0, array.length)

Method 4: Use a loop and pop all the elements from the array.


62. Check if a variable is an integer or not?


num =20

63. Write a function that accepts two strings and check if they are anagrams of one another.


function check_anagram(str_1, str_2)
    let a= str_1.toLowerCase();
    let b = str_2.toLowerCase();

    a= a.split("").sort().join("");
    b= b.split("").sort().join("")
    return a===b;

64. What would be the output of this code?

0.1+0.2 === 0.3;



This happens because of floating-point errors in the internal representation.


With this, we conclude all the interview questions and answers, we hope these questions will help you during the interview. If you have appeared in any JavaScript interview in past few months or years please comment down the questions you faced and we will add them in the list with the appropriate answers.

We also recommend you go through these top front-end interview questions to refresh your knowledge on other front-end technologies.

If you like this article or have any suggestions please comment down below.

People are also reading:

Leave a Reply

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