Those are the elements of the array. The name refers to the array, not the elements.
The function is anonymous and has no name, nor any need of one. animal is known as the function parameter. Since map is an iterator, it will iterate the object array, animals and perform an action on each element, animal.
Note there is no name given to the function (which is what anonymous means).
The new arrow syntax eliminates the function keyword but keeps the parameter container. When there is exactly one parameter we are permitted to drop the parentheses. We can also leave off the curly braces and the return keyword if our function body contains only one statement or expression.
Hey @mtf, I read above that .map() refers to First Letter of string as String itself acts as Array. But if that’s true, why it’s not Upper Casing only first letters of one, two etc. Why does it upper case entire word then? These are also strings. Please clarify if I am missing something.
hello everyone
i didnt understand so much what do i need to do in the The .map() Method exersie.
i the first step they askes us to write a code that create a new array that contains the first character of each string in the animals array. i wrote
I’ve been trying to do this lesson but I am confused why the colors of the words are very different from the example images when I write the exact same thing. I can’t imagine what I would be doing wrong that it doesn’t match.
(param1, param2, …, paramN) => { statements }
(param1, param2, …, paramN) => expression
// equivalent to: => { return expression; }
// Parentheses are optional when there's only one parameter name:
(singleParam) => { statements }
singleParam => { statements }
// The parameter list for a function with no parameters should be written with a pair of parentheses.
() => { statements }
we can see the shorthand you attempt to use:
(param1, param2, …, paramN) => expression
see? No return keyword used. When omitting the curly brackets, the return keyword also has to be left out. The return becomes implicit.