What is the output of the following JavaScript code? | Question 19

69. What will be the output of the following JavaScript 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>
  1. Result: 10,20,30
  2. Result: 10*10,20*20,30*30
  3. Result: 100,400,900
  4. ValueError

Answer: C) Result: 100,400,900

Explanation:

In the above JavaScript code, we used the map() method which is used to create a new array by performing a function on each array element, and in the myFunction() we are multiplying the elements with the same value. Thus, the output would be "Result: 100,400,900".

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.