JavaScript MCQs with answers Page - 24

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. Which JavaScript method is used to call a function (a callback function) once for each array element?

  • (A) for()
  • (B) traverse()
  • (C) forEach()
  • (D) foreach()

A

Admin • 833K Points
Coach

Q. What will be the output of the following JavaScript code?

Code:
<script>
	const arr = [10, 20, 30];
	let result = 0;
	
	arr.forEach(myFunction);
	
	document.write("Result: " , result)
	function myFunction(value, index, array) {
	  result += value; 
	}
</script>
  • (A) Result: 60
  • (B) Result: 102030
  • (C) Result: 10,20,30
  • (D) ValueError

A

Admin • 833K Points
Coach

Q. What will be the output of the following JavaScript code?

Code:
<script>
	const values = [10, 20, 30];
	const result = values.map(myFunction);

	document.write("Result: ", result);

	function myFunction(value, index, array) {
	  return value * value;
	}
</script>
  • (A) Result: 10,20,30
  • (B) Result: 10*10,20*20,30*30
  • (C) Result: 100,400,900
  • (D) ValueError

A

Admin • 833K Points
Coach

Q. Which JavaScript method is used to create a new array with array elements that passes a test?

  • (A) forEach()
  • (B) map()
  • (C) forMap()
  • (D) filter()

A

Admin • 833K Points
Coach

Q. Which JavaScript object works with the dates?

  • (A) Date
  • (B) DateTime
  • (C) date
  • (D) dateTime

A

Admin • 833K Points
Coach

Q. Which JavaScript statement(s) is correct to create Date object(s) with new Date() constructor?

  • (A) new Date()
  • (B) new Date(year, month, day, hours, minutes, seconds, milliseconds)
  • (C) new Date(milliseconds)
  • (D) All of the above

A

Admin • 833K Points
Coach

Q. What will be the output of the following JavaScript code?

Code:
<script>
	const curr = new Date();
	document.write(curr);
</script>
  • (A) Tue Dec 21 2021 13:04:36 GMT+0530
  • (B) Tue Dec 21 2021 13:04:36 (India Standard Time)
  • (C) Tue Dec 21 2021 13:04:36::00::01 GMT+0530 (India Standard Time)
  • (D) Tue Dec 21 2021 13:04:36 GMT+0530 (India Standard Time)

A

Admin • 833K Points
Coach

Q. Which JavaScript method is used to convert a date to a UTC string (a date display standard)?

  • (A) toUTCString()
  • (B) toUtcString()
  • (C) utcString()
  • (D) toutcstring()

A

Admin • 833K Points
Coach

Q. The internal clock in JavaScript counts from midnight _____.

  • (A) January 1, 1972
  • (B) January 1, 1947
  • (C) January 1, 1980
  • (D) January 1, 1970

A

Admin • 833K Points
Coach

Q. Which method is used to get the year of a date as a four-digit number?

  • (A) getYear()
  • (B) fullYear()
  • (C) getFullYear()
  • (D) getfullyear()

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