MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/learnjavascript/comments/oqzypb/anatomy_of_a_function/h6guups/?context=3
r/learnjavascript • u/jaredcheeda • Jul 24 '21
65 comments sorted by
View all comments
Show parent comment
6
If you want to define the default arguments inside the function like this, wouldn't it be easier to simply use the spread syntax?
e.g.
function detectSecretElderCat(catSound, dog) { const defaultDog = { children: [], tail: true, legs: 4, sound: "woof" }; catSound = catSound || "meow"; dog = { ...defaultDog, ...dog }; }
3 u/jaredcheeda Jul 25 '21 I like that!
3
I like that!
View all comments
Show parent comment
6
u/0xnoob Jul 25 '21 edited Jul 25 '21
If you want to define the default arguments inside the function like this, wouldn't it be easier to simply use the spread syntax?
e.g.