Home »
MCQs »
JavaScript MCQs
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>
- Result: 10,20,30
- Result: 10*10,20*20,30*30
- Result: 100,400,900
- 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".