Home »
MCQs »
JavaScript MCQs
What is the output of the following JavaScript code? | Question 15
64. What will be the output of the following JavaScript code?
<script>
var values = [10, 20, 30, 40];
var result = values.reduceRight(function(x,y){
return (x + y);
});
document.write("Result: " + result);
</script>
- Result: 40
- Result: 70
- Result: 90
- Result: 100
Answer: D) Result: 100
Explanation:
In the above JavaScript code, we used the reduceRight() method which is used to reduce the given array elements into a single value by executing a reducer function. The reducer() function is applied against the accumulator and reduces all the elements from right to left. Thus, the output would be "Result: 100".