I don’t really understand this. So in this case num has to be num specifically or can it be anything else? I mean can I use another word (like number, cat etc) instead of num?
A variable name is a label, so yes, it can be anything you like. Suggest keep it sensible and object oriented. Describe the contents with as brief a name as one can. Remember, variables are not values, they refer to values.
})
im confused as to why, first[0] , in this situation gives the first letter of every word in the array and not, ‘Hen’ , if i console.log(animals.length) the length of the array is 10. wouldnt that put ‘Hen’ at first[0]? idk .length is counting the elements in the array. how does .map() knwo to grab the first letter of all the elements with first[0]? thank you
From what I understand about arrow functions, I shouldn’t need to explicitly state return or surround the function body in brackets. What am I missing?
Hi,
I wrote : -
const secretMessage = animals.map(animal => animal[0]); and it worked but when I rewrote this as : const secretMessage = animals.map(animal => animal.at(0)); it gave the following error : -
TypeError: animal.at is not a function at animals.map.animal
I expected the String function at() to work since the callback function was having String object instances as input. Can someone kindly explain where I am going wrong here. Thanks in advance.