TOP CATEGORIES

×

Top 50 most asked JavaScript interview questions

JavaScript Interview Questions

JavaScript is a client-side as well as a server-side scripting language. It was created by Brendan Eich in the year of 1995. 


JavaScript is an object-based, lightweight, and cross-platform translated language, it is responsible for translating the JavaScript code for the web browser. JavaScript is a completely different language from the Java language.

List of Most Asked JavaScript Interview Questions


JavaScript interview questions have been designed specially to get you to make familiar with the nature of questions you may experience during your interview for the subject of JavaScript. In this section, we have listed basically three levels of JavaScript interview questions such as:

  1. JavaScript Interview Questions for Beginners
  2. JavaScript Interview Questions for Intermediate
  3. JavaScrip Interview Questions for Advanced

Q1 Which company developed JavaScript and When?

"Netscape" software company is developed JavaScript in "1995".

Q2 Is JavaScript a case-sensitive language?

YES! JavaScript is a case-sensitive language. It means that language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters in JavaScript language.

Q3 What is the difference between Java & JavaScript?

  • Java is a complete Object-Oriented Programming (OOPS) language but JavaScript is an Oops scripting language that can be introduced to HTML pages.
  • Java creates applications that run in a virtual machine or browser but JavaScript code is run on a browser only.
  • Java code needs to be compiled before running it but JavaScript codes are all in the form of text.

Q4 What is the name of JavaScript data types?

There are the following data types supported in JavaScript:

  • Number
  • String
  • Boolean
  • Object
  • Undefined
  • Symbol
  • Null

Q5 How to read & write the properties of an object in JavaScript?

By using the dot(.) notation you can read and write the properties of an object in JavaScript.

Q6 What are the advantages of using JavaScript?

  • Less Server Interaction: The Less Server Interaction is used to save server traffic that means validating user input before sending the page off to the server.
  • Immediate Feedback to the Visitors: They don't have to wait for a page reload to see if they have forgotten to enter something.
  • Increased Interactivity: Increase interactivity means that create interfaces that react when the user hovers over them with a mouse or activates them via the keyboard.
  • Richer Interfaces: Use JavaScript to include such items as drag-and-drop components and sliders to give a Rich Interface to your site visitors.

Q7 What are the disadvantages of using JavaScript?

  • JavaScript is not supported for multithreading and multiprocessing.
  • In JavaScript, reading and writing files are not allowed.
  • No support for networking applications in JavaScript.

Q8 How to write a simple script in JavaScript?

JavaScript code always write in between the open <script> & close </script>  script tag.

Example of JavaScript Code

<script type="text/javascript">

   document.write("Hello! JavaScript");

</script>

Q9 What is a prompt box?

A prompt box in JavaScript allows the user to enter input by providing a text box.

Q10 How to write a comment in JavaScript?

The comment allows to descript about code OR instructs about code. Actually, the comment is not visible OR display when the code runs on the browser. For example, if the coder wants some descriptions about code but doesn't want to show those descriptions after running the page on the browser then simply hide codes by using comments.

Types of Comments in JavaScript

  • Single-Line Comment: It is started by double forward slash "//".
  • Multi-Line Comment: It is started with an asterisk symbol like /* write a comment here */.

Q11 What is the purpose of the 'this' keyword?

In JavaScrip, the 'this' keyword is used to always refer to the current context.

Q12 What is closure in JavaScript

The closure is created in JavaScript when a variable that is defined outside the scope in reference is accessed from some inner scope.

<script type="text/javascript">

    var i = 10;

    function sum() {

       document.writeln("i+i");

    }

    sum();    //===> 20

</script>

Q13 What is variable typing in JavaScript?

The variable typing is used to assign any characteristics and the same variable used for a number, or quantity to a variable, it's called variable typing in JavaScript.

<script type="text/javascript">

    var i = 1;

    var i = "string";

</script>

Q14 What are the types of Functions in JavaScript?

In JavaScript, Two "types of Functions" are used:

  • Named
  • Anonymous

Q15 What is the difference between 'var' and 'let' keywords in JS?

  • var: It is used to declare a variable in javascript, the difference 'var' has function scope.
  • let: It is also used to declare a variable in javascript, It has block scope.

Q16 What is the difference between defined & undefined variables in JavaScript?

Defined Variable

Use a variable that exist and it has been declared with a value, then JavaScript will return the value of the variable. The declaration of variable like typeof undeclared_variable = value of the variable, this will return defined variable:

<script type="text/javascript">

    var x = 10;

    console.log(x);    // output ===> 10; defined variable

</script>

Undefined Variable

Use a variable that doesn't exist and has not been declared, then JavaScript will throw an error var name is not defined and script will stop executing. Declaration like typeof undeclared_variable, then it will return undefined variable:

<script type="text/javascript">

    var x;

    console.log(x);  // output ===> undefined variable

</script>

Q17 What are the phases of Event Propagation?

The Event Propagation has divided into three phases.

  1. Capturing Phase
  2. Target Phase
  3. Bubbling Phase

Q18 What's the difference between == and === ?

  • == OR Abstract Equality: It is used to compare by value after coercion.
  • === OR Strict Equality: It is used to compare by value and type without coercion.

Q19 How to empty an array in JavaScript?

1st needs to create an empty array (arrayList1 =[], arrayList2 = []). The name of an arrayList1 & arrayList2, after that declaration the value of arrayList1 for more understanding see the below mentioned example.

<script type="text/javascript">

    var arrayList1 = ['p', 'q', 'r', 's', 't']; // A array declaration

    var arrayList2 = arrayList1;  // Referenced arrayList1 by another variable arrayList2

    arrayList1 = []; // Now arrayList1 is empty 

    console.log(arrayList2); // Output ['p', 'q', 'r', 's', 't']

</script>

Q20 What is the Scope in JavaScript?

The Scope is the area where you are able to declare variables OR able to write functions, and valid to access all it; this is called Scope in JavaScrip. Basically, JavaScript has three types of Scopes:

  • Global Scope
  • Function Scope
  • Block Scope

Email: advertise@gdatamart.com

Donate: To Support US

© 2024 GDATAMART.COM (All Rights Reserved)