JavaScript MCQs with answers Page - 20

Here, you will find a collection of MCQ questions on JavaScript. Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

A

Admin • 832.27K Points
Coach

Q. Which property is used to define the HTML content to an HTML element with a specific id?

  • (A) innerText
  • (B) innerContent
  • (C) elementText
  • (D) innerHTML

A

Admin • 832.27K Points
Coach

Q. Which JavaScript method is used to write HTML output?

  • (A) document.write()
  • (B) document.output()
  • (C) console.log()
  • (D) document.writeHTML()

A

Admin • 832.27K Points
Coach

Q. Which JavaScript method is used to write into an alert box?

  • (A) window.alertHTML()
  • (B) window.alert()
  • (C) window.alertBox()
  • (D) window.alertContent()

A

Admin • 832.27K Points
Coach

Q. Which is the correct JavaScript statement to print the addition of two numbers 10 and 2o in a paragraph whose id is "result"?

  • (A) getElementById("result").innerHTML = 10+20;
  • (B) getElementById("result").innerHTML = "10+20";
  • (C) getElementById("#result").innerHTML = 10+20;
  • (D) All of the above

A

Admin • 832.27K Points
Coach

Q. What is the use of this JavaScript statement?

Code:
<button onclick="window.print()">Submit</button>
  • (A) It will write "Submit" on the current Window
  • (B) It will print the content of the current page
  • (C) It will write the content of the current page in the browser’s console
  • (D) None of the above

A

Admin • 832.27K Points
Coach

Q. In JavaScript, single line comment begins with ___.

  • (A) #
  • (B) /*
  • (C) $
  • (D) //

A

Admin • 832.27K Points
Coach

Q. In JavaScript, multi-line comments start with __ and end with ___.

  • (A) /* and */
  • (B) <!—and -->
  • (C) ## and ##
  • (D) // and //

A

Admin • 832.27K Points
Coach

Q. Which JavaScript keyword is used to declare a variable?

  • (A) Var
  • (B) var
  • (C) Let
  • (D) All of the above

A

Admin • 832.27K Points
Coach

Q. How many keywords are there in JavaScript to declare variables or constants?

  • (A) 1
  • (B) 2
  • (C) 3
  • (D) 4

A

Admin • 832.27K Points
Coach

Q. What is the main difference between var and let keywords in JavaScript?

  • (A) var defines a variable while let defines a constant
  • (B) var defined function scoped variable while let define block scoped variable
  • (C) The value of a variable declared with var can be changed while the value of a variable declared with let cannot be changed
  • (D) All of the above