JavaScript MCQ Quiz - Objective Question with Answer for JavaScript - Download Free PDF

Last updated on Aug 21, 2022

Latest JavaScript MCQ Objective Questions

JavaScript MCQ Question 1:

In JavaScript "= = =" operator defines what?

  1. Non-identical
  2. Is identical (is equal to and is of the different type)
  3. Is identical (is equal to and is of the same type)
  4. Is equal to

Answer (Detailed Solution Below)

Option 3 : Is identical (is equal to and is of the same type)

JavaScript MCQ Question 1 Detailed Solution

The correct answer is option 3.

Concept:

  • In JavaScript "= = =" operator defines Is identical (is equal to and is of the same type). 
  • The === operator in javascript compares the equality of two operands with type.
  • If both type and value are equal, the condition is true; otherwise, it is false. 
  • In javascript, the equality operator is used to check if two values are equal. In javascript, the comparison is done with the == and === operators.
  • The fundamental difference between the == and === operators in javascript is that the == operator converts the operands' types before comparing them, whereas the === operator compares the operands' values as well as their data types.
  • The type conversion of the operand is the major difference between == and === in Javascript.

Syntax for equality:

x === y

Example:

let a = 10;

let b = '10';

let c = 10;

console.log(a===b); //output: false;

console.log(a===c); //output: true;

Syntax for equality:

x == y

Example:

let a = 10;

let b = '10';

let c = 10;

console.log(a===b); //output: true;

console.log(a===c); //output: true;

Hence the correct answer Is identical (is equal to and is of the same type).

JavaScript MCQ Question 2:

Which one of the following is not considered as an error in JS

  1. Syntax error
  2. Missing of semicolons
  3. Division by zero
  4. Missing of Bracket
  5. Wrong keyword

Answer (Detailed Solution Below)

Option 3 : Division by zero

JavaScript MCQ Question 2 Detailed Solution

Concept:

Division of any integer by zero is not an error in the JavaScript. It just prints the infinity as a result. However, there is an exception in JavaScript, dividing zero with zero will not have any defined number/value so, the result of this specific operation is a special value "Not a Number" (or NaN) and printed as NaN.

JavaScript MCQ Question 3:

What will be the result of the following JavaScript: var x="Volvo"+16+4

  1. 164volvo
  2. Volvo164
  3. volvo20
  4. 20volvo
  5. Error

Answer (Detailed Solution Below)

Option 2 : Volvo164

JavaScript MCQ Question 3 Detailed Solution

Answer: Option 2

Concept:

  • The JavaScript Programming language came into existence in 1995.
  • JavaScript is a programming language used in web development.
  • It was developed by Netscape to add dynamic and interactive elements to websites. 
  • JavaScript is influenced by Java.
  • It is a client-side scripting language.
  • A JavaScript code can be inserted anywhere within the HTML of a webpage.
  • JavaScript is a scripting language that is used to develop websites.
  • JavaScript helps to add functionality and behaviors to your website, allowing your website’s visitors to interact with content in many imaginative ways.
  • In September 1995, a Netscape programmer named Brandan Eich developed a new scripting language in just 10 days.
  • It was originally named Mocha, but quickly became known as LiveScript and, later, JavaScript.

Explanation:

 

The Behaviour Of Operator “+” in JavaScript:

If any of the operands is a string, all others are converted to a string, and concatenation is done, otherwise, arithmetic addition is done.

for example if the var x =  16+ "Volvo"+ 4; is given then output will be 16Volvo4.

JavaScript MCQ Question 4:

How can you write into HTML output using Java Script?

  1. Using innerHTML
  2. Using console.log()
  3. Using document.write()
  4. Using window.alert()
  5. None of above

Answer (Detailed Solution Below)

Option 3 : Using document.write()

JavaScript MCQ Question 4 Detailed Solution

Answer: Option 3

Concept:

  • The write() method writes HTML expressions or JavaScript code to a document
  • In Javascript, document.write(" ") at client side and response.write on server side

Additional Information

innerHTML

This property used to return/set the content of any HTML element.

console.log()

This method is used to write output to the browser's console.

This is generally used while testing the web application.

window.alert()

This method is used to display a dialog box to the user to alert the user about something.

An alert dialog box is mostly used to give a warning message to the users. 
for example, an input field requires to enter some text but the user does not enter that field then as a part of validation we can use alert box to give warning message.

JavaScript MCQ Question 5:

Any time you include JavaScript verbiage in HTML document, you must enclose those lines inside a ______ tag pair.

  1. < Div > and < / Div >
  2. < Body > and < / Body >
  3. ​< Script > and < / Script >
  4. < HTML > and < / HTML >
  5. < p > and < /p >

Answer (Detailed Solution Below)

Option 3 : ​< Script > and < / Script >

JavaScript MCQ Question 5 Detailed Solution

Answer: Option 3

Explanation:

Option 1: < Div > and < / Div >

This is not correct. as this pair used to create a division in an HTML page/document. 

Option 2: < Body > and < / Body >

This is not correct. as body tag used to define the body of HTML page.

Option 3: ​