JavaScript Multiple Choice Quiz

Question 1: What does JavaScript primarily add to a web page?

  • A) Style
  • B) Interactivity
  • C) Structure
  • D) Images

Answer: B) Interactivity

Question 2: What is the correct way to declare a variable in JavaScript?

  • A) let myVar = 10;
  • B) var myVar = 10;
  • C) const myVar = 10;
  • D) all of the above

Answer: D) all of the above

Question 3: Which of the following is a falsy value in JavaScript?

A) 0

B) “false”

C) undefined

D) all of the above

Answer: D) all of the above

Question 4: What is the purpose of the document.getElementById() method in JavaScript?

A) To get the value of an input element

B) To change the page’s title

C) To get an element by its ID

D) To add a new HTML element

Answer: C) To get an element by its ID

Question 5: Which operator is used for equality without type coercion in JavaScript?

A) ===

B) ==

C) =

D) !==

Answer: A) ===

Question 6: What is the correct way to comment a single line in JavaScript?

A) // This is a comment

B) /* This is a comment */

C)

D) % This is a comment %

Answer: A) // This is a comment

Question 7: Which function is used to add a new element at the end of an array in JavaScript?

A) push()

B) pop()

C) shift()

D) unshift()

Answer: A) push()

Question 8: What is the purpose of the setTimeout() function in JavaScript?

A) To set the text of an element

B) To execute a function after a specified delay

C) To change the color of an element

D) To create a new object

Answer: B) To execute a function after a specified delay

Question 9: Which of the following is not a valid JavaScript data type?

A) String

B) Object

C) Function

D) Character

Answer: D) Character

Question 10: What does the addEventListener() method do in JavaScript?

A) Adds a new element to the page

B) Adds a click event to an element

C) Changes the page’s background color

D) Removes an element from the page

Answer: B) Adds a click event to an element

Leave a Reply

Your email address will not be published. Required fields are marked *