Tell us what’s happening:
I think I understand REST-parameters. But some things are still confusing for me.
So I tried 3 things. To test this.
Test 1: Above you can see that you cannot put a string and array in 1 sentence. Which makes sense that it doesn’t work
Test 2: Above you can see that the REST parameter takes the arguments and puts them into an array.
Test3 + QUESTION: Why am I not getting an array here or undefined?
BTW: Starting to love freeCodeCamp, you have my donation for sure !! Good excercises + good projects + good support !!
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36
Challenge: Use the Rest Parameter with Function Parameters
Link to the challenge:
lasjorg
February 28, 2022, 12:56am
2
Please post code and not images.
Use a comma ,
to separate the log values instead. I assume toString is called on the array when doing string concatenating.
const sum = (...args) => {
console.log(Array.isArray(args))
console.log(args)
console.log('testing ' + args + ' testing')
console.log('testing ', args, ' testing')
console.log('testing ', args.toString(), ' testing')
}
console.log(sum(1,2,3))
// true
// (3) [1, 2, 3]
// testing 1,2,3 testing
// testing (3) [1, 2, 3] testing
// testing 1,2,3 testing
When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>
) to add backticks around text.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).
1 Like
Very good example! oke thank you very much! You explained it very well!
And yes will not post Images anymore.
Thanks @lasjorg !!
1 Like
system
Closed
August 29, 2022, 1:40pm
4
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.