0

This probably suits other methods as well but the one i'm using at the moment is map().

How come:

const singleFruit = fruits.map((fruit) => fruit.toUpperCase());
console.log(singleFruit);

returns the array the correct way, with everything in uppercase, when:

const singleFruit = fruits.map((fruit) => {
fruit.toUpperCase();
});
console.log(singleFruit);

gives me an array but with my assigned fruits are now undefined. I can solve this by adding return before "fruit.toUpperCase();" I thought that the second code was the exact same as the first one but without the curly braces.

Thanks!

Vic
  • 3
  • 2
  • 2
    without the `{}` the return is implied - with `{}` you need to return the mapped something - [read the docs]9https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) :p – Jaromanda X Oct 06 '20 at 11:22
  • Then what is the question? – Aakif Oct 06 '20 at 11:23
  • this seems like you found something out and want to share it with us instead of to ask something – bill.gates Oct 06 '20 at 11:24
  • When you use {} then you need to use return keyword but if you just want to change element ust without {} as @JaromandaX said. – Khalil Oct 06 '20 at 11:24

0 Answers0