6
Doing some exercises, I realized that it is possible to use the map function in a Rest that apparently only returns pure elements. also realized that it is not possible to apply a typeof nor foreach.
Can anyone explain why? I would like to know:
what exactly Rest returns
why it is possible to apply a map, but not a foreach
why when in the console, apparently Rest only returns "pure elements"
sample code:
const arr = ["ana", "carlos", "rafael"]
console.log(...arr) // <- retorna os elementos apenas, sem array
console.log(...arr.map(e => e.toUpperCase())) // <- é possível usar map, como se fosse uma array
console.log(...arr.forEach(e => e.toUpperCase())) // <- não é possivel usar forEach...
Hmm thanks buddy, I was cracking my head on this. But I still have one doubt left... are to say that the spread operator, even located in front of the elements, it only returns something after the return of the elements in front of him to it?
– lucas F
Basically yes. He’s not a real operator (it’s kind of complicated to explain), but may consider that he runs last.
– bfavaretto