I am currently completing the Intermediate JavaScript code challenges and ran into an issue which I don’t fully understand because my answer appears to be the same as the answer from the solution with a few tweaks in the code.
I spent a couple of hours trying to do this question thinking I didn’t have a good grasp on how to use these methods. After this I feel I do have a good grasp, I am just missing something to develop my understanding a bit better.
Why does my answer with the curly brackets return undefined when it is still the right way of writing a function, just not the concise way.
Hi, Moiza.
I’m going to attempt to answer your question. I think the reason is because the Codecademy answer uses the simple expression of an arrow function declared on one line and so does not need the “return” keyword because it is implicit.
Yours is a multiline statement and so you should explicitly use “return” inside your function: return arr1.filter(…), without which it returns “undefined”. Cheers
I was able to refactor the code. I got rid of the extra curly braces in the version that took more than a line.
I don’t know Javascript well so I don’t know about the filter function, but without !.return statement, the output was “undefined”.