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

Last updated on Apr 13, 2023

Latest JavaScript MCQ Objective Questions

JavaScript Question 1:

Which of the following is not a built-in module in Node.js?

  1. fs
  2. http
  3. mysql
  4. path

Answer (Detailed Solution Below)

Option 3 : mysql

JavaScript Question 1 Detailed Solution

Node.js

  • Node.js is a platform that allows developers to write server-side JavaScript applications using the same language and runtime environment as front-end web development.
  • Node.js comes with several built-in modules that provide functionality for common tasks, such as working with files (fs), creating HTTP servers (http), and managing file paths (path).
  • These built-in modules can be used in Node.js applications without any additional installation.

mysql module

  • The mysql module, on the other hand, is not a built-in module in Node.js.
  • It is a third-party module that provides a way for Node.js applications to communicate with MySQL databases.
  • In order to use the mysql module, it must be installed separately via the npm (Node Package Manager) tool, which is included with Node.js.
  • This can be done by running the command 'npm install mysql' in a terminal or command prompt window.

Hence, the correct answer is option 3.

JavaScript Question 2:

A 2D array having a different number of elements in each row is known as ________.

  1. Spares
  2. Danes
  3. Regular
  4. Irregular

Answer (Detailed Solution Below)

Option 4 : Irregular

JavaScript Question 2 Detailed Solution

Spares - There is no such term related to arrays in programming.

Danes - There is no such term related to arrays in programming.

Regular - A regular array is a 2D array where each row has the same number of elements.

Irregular - An irregular array, also known as a jagged array, is a 2D array where each row can have a different number of elements. This type of array can be useful in situations where you have data that does not fit neatly into a rectangular shape, such as when dealing with data of varying lengths or when representing a hierarchical structure. In C++, an irregular array can be implemented as an array of arrays, where each sub-array can have a different size.

  • A 2D array having a different number of elements in each row is known as an "irregular" array.

JavaScript Question 3:

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 Question 3 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 Question 4:

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 Question 4 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 Question 5:

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

Top JavaScript MCQ Objective Questions

_______ among the following is a Language of JavaScript.

  1. text/JavaScript
  2. text/ECMAScript
  3. text/VBScript
  4. JavaScript VBScript

Answer (Detailed Solution Below)

Option 1 : text/JavaScript

JavaScript Question 6 Detailed Solution

Download Solution PDF

The correct answer is text/JavaScript.

Key Points

  • The programming language JavaScript is one of the foundational elements of the World Wide Web. 
  • JavaScript is an ECMAScript-compliant high-level, frequently just-in-time compiled language.
  • It features first-class functions, prototype-based object orientation, and dynamic typing.
  • It supports event-driven, functional, and imperative programming paradigms and is a multi-paradigm.
  • It offers application programming interfaces (APIs) for using the Document Object Model, regular expressions, dates, and standard data structures.

Additional Information

  • ECMAScript:
    • A JavaScript standard called ECMAScript was created to guarantee browser compatibility for web pages.
  • VBScript:
    • Microsoft created VBScript, an Active Scripting language based on Visual Basic. 

Which state has been linked with Himachal Pradesh under 'Ek Bharat Shreshtha Bharat' program to promote national unity through mutual understanding as on 30 June 2020?

  1. West Bengal
  2. Goa
  3. Gujarat
  4. Kerala

Answer (Detailed Solution Below)

Option 4 : Kerala

JavaScript Question 7 Detailed Solution

Download Solution PDF

The correct answer is Kerala.

  • Kerala has linked with Himachal Pradesh under Ek Bharat Shreshtha Bharat.
  • The program aims to actively enhance interaction between people of diverse cultures living in different States and UT's in India.
  • This is a part of Ek Bharat Shrestha Bharat activities, Ministry of Tourism.

Important Points

State and its linkage state under 'EK Bharat Shreshtha Bharat'
State Paired State/UTs
Goa Jharkhand
Gujarat Chhattisgarh
Karnataka Uttarakhand

 

Key Points

  •  The mission of Ek Bharat Shreshtha Bharat:
    • To Celebrate the Unity in the Diversity of our Nation and to maintain and strengthen the fabric of traditionally existing emotional bonds between the people of our Country.
    • To promote the spirit of national integration through a deep and structured engagement between all Indian States and Union Territories.
    • To Showcase the rich heritage and culture, customs, and traditions of either State for enabling people to understand and appreciate the diversity that is India.
    • To establish long-term engagements and, to create an environment that promotes learning between States/UTs by sharing best practices and experiences.

The correct syntax to write "Hi There" in Javascript is

  1. jscript.write ("Hi There")
  2. response.write ("Hi There")
  3. print ("Hi There")
  4. print.jscript ("Hi There")

Answer (Detailed Solution Below)

Option 2 : response.write ("Hi There")

JavaScript Question 8 Detailed Solution

Download Solution PDF

The correct answer is “option 2”.

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

Explanation:

All options 1, 3 & 4 are having the wrong syntax.

Hence, the correct syntax is response.write("Hi There").

JavaScript Question 9:

_______ among the following is a Language of JavaScript.

  1. text/JavaScript
  2. text/ECMAScript
  3. text/VBScript
  4. JavaScript VBScript

Answer (Detailed Solution Below)

Option 1 : text/JavaScript

JavaScript Question 9 Detailed Solution

The correct answer is text/JavaScript.

Key Points

  • The programming language JavaScript is one of the foundational elements of the World Wide Web. 
  • JavaScript is an ECMAScript-compliant high-level, frequently just-in-time compiled language.
  • It features first-class functions, prototype-based object orientation, and dynamic typing.
  • It supports event-driven, functional, and imperative programming paradigms and is a multi-paradigm.
  • It offers application programming interfaces (APIs) for using the Document Object Model, regular expressions, dates, and standard data structures.

Additional Information

  • ECMAScript:
    • A JavaScript standard called ECMAScript was created to guarantee browser compatibility for web pages.
  • VBScript:
    • Microsoft created VBScript, an Active Scripting language based on Visual Basic. 

JavaScript Question 10:

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 Question 10 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 Question 11:

Which state has been linked with Himachal Pradesh under 'Ek Bharat Shreshtha Bharat' program to promote national unity through mutual understanding as on 30 June 2020?

  1. West Bengal
  2. Goa
  3. Gujarat
  4. Kerala

Answer (Detailed Solution Below)

Option 4 : Kerala

JavaScript Question 11 Detailed Solution

The correct answer is Kerala.

  • Kerala has linked with Himachal Pradesh under Ek Bharat Shreshtha Bharat.
  • The program aims to actively enhance interaction between people of diverse cultures living in different States and UT's in India.
  • This is a part of Ek Bharat Shrestha Bharat activities, Ministry of Tourism.

Important Points

State and its linkage state under 'EK Bharat Shreshtha Bharat'
State Paired State/UTs
Goa Jharkhand
Gujarat Chhattisgarh
Karnataka Uttarakhand

 

Key Points

  •  The mission of Ek Bharat Shreshtha Bharat:
    • To Celebrate the Unity in the Diversity of our Nation and to maintain and strengthen the fabric of traditionally existing emotional bonds between the people of our Country.
    • To promote the spirit of national integration through a deep and structured engagement between all Indian States and Union Territories.
    • To Showcase the rich heritage and culture, customs, and traditions of either State for enabling people to understand and appreciate the diversity that is India.
    • To establish long-term engagements and, to create an environment that promotes learning between States/UTs by sharing best practices and experiences.

JavaScript Question 12:

By default, when you use Page Output Caching, at what location page is cached?

  1. Only on web server
  2. Only on Client
  3. Web server, any proxy servers, and browser
  4. All of the above.

Answer (Detailed Solution Below)

Option 3 : Web server, any proxy servers, and browser

JavaScript Question 12 Detailed Solution

Concept:

If you are using Page Output Caching By default, a page is cached in three locations: web server, any proxy servers, and browser.Location attribute is used in <%@ OutputCache %> directive to specify where a page is cached.

This attribute has the following values:

  • Any
  • Client
  • Downstream
  • None
  • Server
  • ServerAndClient

JavaScript Question 13:

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 >

Answer (Detailed Solution Below)

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

JavaScript Question 13 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: ​