JavaScript MCQ Questions and Answers

11. When the interpreter encounters empty statements, what it will do:

  1. Shows a warning
  2. Prompts to complete the statement
  3. Throws an error
  4. Ignores the statements

Answer : D
Explanation: In JavaScript, when the interpreter encounters an empty statement it normally ignores or don’t respond to that empty statement. The empty statements also sometimes very useful like we use the empty statements for creating a loop for nothing.

12. Which of the following code creates an object?

  1. var book = Object();
  2. var book = new Object();
  3. var book = new Book();
  4. var book = new OBJECT();

Answer : B
Explanation: var book = new Object(); will create an object.

13. JavaScript is designed for the following purpose:

  1. To style HTML pages
  2. To execute Queries related to databases on a server
  3. To add interactivity to html pages
  4. All of the above

Answer : D
Explanation: JavaScript is designed for all of the following purposes: to style HTML pages, to execute Queries related to databases on a server, to add interactivity to HTML pages, to perform server side scripting operations, etc.

14. The meaning for augmenting classes is that

  1. objects inherit prototype properties in static state
  2. objects inherit prototype properties only in dynamic state
  3. objects inherit prototype properties even in dynamic state
  4. None of the mentioned

Answer : C
Explanation: Objects inherit prototype properties even in dynamic state, JavaScript’s prototype-based inheritance mechanism is dynamic: an object inherits properties from its prototype, even if the prototype changes after the object is created. This means that we can augment JavaScript classes simply by adding new methods to their prototype objects and hence option C is correct.

15. What is the correct JavaScript syntax to write “Hello World”?

  1. System.out.println(“Hello World”)
  2. document.write(“Hello World”)
  3. println (“Hello World”)
  4. response.write(“Hello World”)

Answer : B
Explanation: document.write(“Hello World”) is the correct JavaScript syntax to write “Hello World”.

16. How we write “Hello World” in an alert box?

  1. alertBox(“Hello World”);
  2. msgBox(“Hello World”);
  3. msg(“Hello World”);
  4. alert(“Hello World”);

Answer : D
Explanation: alert(“Hello World”);

17. Why JavaScript is called as Lightweight Programming Language?

  1. because we can add programming functionality inside JS
  2. because JS is client side scripting
  3. because JS can provide programming functionality inside but up to certain extend
  4. because JS is available free of cost

Answer : C
Explanation: JS is called as “Lightweight Programming Language” because it can include programming functionality but does not perform stronger operations like Java and C++.

18. To include external JS code inside an HTML document which attribute is used?

  1. src
  2. link
  3. script
  4. ext

Answer : A
Explanation: To include external JS code inside an HTML document src attribute is used.

19. The “function” and ” var” are known as:

  1. Keywords
  2. Special keywords
  3. Declaration statements
  4. Prototypes

Answer : C
Explanation: The “function” and “var” both are the Declaration statements and these both are used for defining, and declaring variable, functions anywhere in the program, and hence option C is correct.

20. Which of the following function of the String object returns the calling string value converted to upper case?

  1. toLocaleUpperCase()
  2. toString()
  3. substring()
  4. toUpperCase()

Answer : D
Explanation: toUpperCase() function of the String object returns the calling string value converted to upper case.

This Post Has 3 Comments

Leave a Reply