JavaScript MCQs with answers Page - 142

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 • 833K Points
Coach

Q. How can you defer script execution until the DOM is loaded?

  • (A) Use defer attribute in script tag
  • (B) Use async attribute
  • (C) Put script at the top
  • (D) Wrap code in alert()

A

Admin • 833K Points
Coach

Q. Which DOM method selects an element by its ID?

  • (A) document.getElementById()
  • (B) document.querySelectorAll()
  • (C) document.getElementByClass()
  • (D) document.findById()

A

Admin • 833K Points
Coach

Q. Which DOM method returns the first element that matches a selector?

  • (A) querySelector()
  • (B) querySelectorAll()
  • (C) getElementById()
  • (D) getElementsByTagName()

A

Admin • 833K Points
Coach

Q. Which object is used to manipulate the HTML document?

  • (A) document
  • (B) window
  • (C) location
  • (D) navigator

A

Admin • 833K Points
Coach

Q. What does the window object represent?

  • (A) The browser window
  • (B) The HTML page
  • (C) The document object
  • (D) The JavaScript engine

A

Admin • 833K Points
Coach

Q. Which method can be used to change the content of an HTML element?

  • (A) innerHTML
  • (B) setAttribute
  • (C) value
  • (D) classList

A

Admin • 833K Points
Coach

Q. Which method adds a new class to an element?

  • (A) classList.add()
  • (B) className.append()
  • (C) setClass()
  • (D) addClass()

A

Admin • 833K Points
Coach

Q. Which method creates a new DOM element?

  • (A) document.createElement()
  • (B) document.newElement()
  • (C) element.create()
  • (D) create()

A

Admin • 833K Points
Coach

Q. Which of the following is a correct way to declare a variable in JavaScript?

  • (A) var myVar;
  • (B) int myVar;
  • (C) let: myVar;
  • (D) declare myVar;

A

Admin • 833K Points
Coach

Q. What will be the output of: console.log(typeof null);

  • (A) null
  • (B) undefined
  • (C) object
  • (D) boolean

Add MCQ in this Category

If you want to share an MCQ question in this category, it's a great idea! It will be helpful for many other students using this website.

Share Your MCQ