Home Videos Exercises MCQ Q&A Quiz Services Sign in

JavaScript Interview Questions And Answers

SOOPRO Pathshala provides JavaScript Interview Questions and Answers


1. What is JavaScript?

It is a light-weighted programming language (“scripting language”) used to develop interactive web pages.


2. What’s the difference between JavaScript and Java?

JavaScript is an object-oriented scripting language.
Java is an object-oriented programming language.

JavaScript does not need compilation before running the application code.
Java source code needs a compiler before it can be ready to run in realtime.


3. What are the features of JavaScript?

These are the features of JavaScript

  • Lightweight interpreted programming language
  • Cross-platform compatible
  • Open-source
  • Object-oriented
  • Integration with other backend and frontend technologies
  • Used especially for development of network-based applications

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

5. How do you create an array in JavaScript?

var a = []; var b = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’];


6. What are the scopes of a variable in JavaScript?

The scope of a variable implies where the variable has been declared or defined in a JavaScript program. There are two scopes of a variable:
Global Scope Global variables, having global scope are available everywhere in a JavaScript code.
Local Scope Local variables are accessible only within a function in which they are defined.


7. What is the ‘this’ keyword in JavaScript?

The this keyword refers to an object.


8. What are the naming conventions for a variable in JavaScript?

Following are the naming conventions for a variable in JavaScript:

  • Variable names cannot be similar to that of reserved keywords. For example, var, let, const etc
  • Variable names cannot begin with a numeric value. They must only begin with a letter or an underscrore character.
  • Variable names are case-sensitive

9. What is Callback?

A JavaScript callback is a function which is to be executed after another function has finished execution.


10. What is Closure?

Closures are created whenever a variable that is defined outside the current scope is accessed from within some inner scope.


11. How does Type Of Operator work?

The type of operator is used to get the data type of its operand.


12. How to create a cookie using JavaScript?

The simplest way to create a cookie is to assign a string value to the document.cookie object.


13. How to read a cookie using JavaScript?

Reading a cookie is just as simple as writing one, because the value of the document.cookie object is the cookie.


14. How to delete a cookie using JavaScript?

You just need to set the expiration date to a time in the past.


15. What is a prompt box?

It is used to display a dialog box with an optional message prompting the user to input some text


16. Is JavaScript a case-sensitive language?

Yes, JavaScript is a case sensitive language.


17. What is the difference between Attributes and Property?

Attributes - provide more details on an element like id, type, value etc.
Property- is the value assigned to the property like type=”text”, value=’Name’ etc.


18. In how many ways a JavaScript code can be placed in an HTML file?

  • Inline
  • Internal
  • External

19. What are the ways to define a variable in JavaScript?

There are three ways to define variables in js are var, const and let


20. What is the difference between innerHTML & innerText?

innerHTML- It will process an HTML tag if found in a string
innerText - It will not process an HTML tag if found in a string.


21. How can you convert the string of any base to integer in JavaScript

The parseInt() function is used to convert numbers between different bases


22. What is NaN in JavaScript?

In JavaScript, NaN is short for "Not-a-Number". In JavaScript, NaN is a number that is not a legal number.


23. Difference between var and let keyword?

In JavaScript programming, the var keyword has been used from the very initial stages of JavaScript.
The Keyword let was added later in ECMAScript 2015 in JavaScript Programming


24. Is javascript a statically typed or a dynamically typed language?

Yes, JavaScript is a dynamically typed language and not statically.


25. Types of erros in JavaScript

Javascript has two types of errors, Syntax error, and Logical error.