Predict the output of the following javascript code
function getAge(...args) {
console.log(typeof args);
}
getAge(21);
Quiz Explanation
In this JavaScript code, a function getAge
is defined with a rest parameter ...args
, which allows the function to accept any number of arguments as an array.
When getAge
is called with getAge(21)
, it passes the argument 21
to the function.
Inside the function, typeof args
is used to determine the type of the args
parameter. Since args
is defined using the rest parameter syntax, it will be an array containing all the arguments passed to the function.
Therefore, the output of the given code will be:
object