-
Notifications
You must be signed in to change notification settings - Fork 32
Open
Description
function tryFruits(...fruits) {
console.log(...fruits);
}
tryFruits('apple', 'banana', 'grapes');
Output:
apple banana grapes
Explanation:
- ...fruits in the function parameter collects all arguments into an array:
fruits = ['apple', 'banana', 'grapes'] - console.log(...fruits) spreads the array into separate arguments,
equivalent to console.log('apple', 'banana', 'grapes'); - console.log prints each argument separated by a space, not as an array.
Note:
If you used console.log(fruits) instead, the output would be:
['apple', 'banana', 'grapes']
Metadata
Metadata
Assignees
Labels
No labels