Home »
MCQs »
JavaScript MCQs
What is the output of the following JavaScript code? | Question 17
66. What will be the output of the following JavaScript code?
<script>
var cars = ["Honda","Hyundai","Mahindra"];
var result = cars.unshift("Toyota", "Tata");
document.writeln("[", result, "] ", cars);
</script>
- [5] Toyota,Tata,Honda,Hyundai,Mahindra
- [5]Honda,Hyundai,Mahindra,Toyota,Tata
- [2] Toyota,Tata
- [5] Honda,Hyundai,Toyota,Tata,Mahindra
Answer: A) [5] Toyota,Tata,Honda,Hyundai,Mahindra
Explanation:
In the above JavaScript code, we used unshift() method which is used to add one or more elements in the beginning of the given array and returns the updated array. This method changes the length of the original array. Thus, the output would be "[5] Toyota,Tata,Honda,Hyundai,Mahindra".