Curious about Javascript map() iterator lesson 3/9

i was working on 3/9 on Iterators lessons and i was curious about something related to the codes for maps. i saw it being written in two ways

// way 1: const smallNumbers = bigNumbers.map( bigNumbers => { return bigNumbers/100; } ) way 2: const smallNumbers = bigNumbers.map( element => { return element/100; } )

why was the element used? and i am a bit confused because it was not a variable anywhere, and i dont understand how it was thrown in just like that and the code still works.

here is the complete code:

const animals = ['Hen', 'elephant', 'llama', 'leopard', 'ostrich', 'Whale', 'octopus', 'rabbit', 'lion', 'dog']; // element here can be replaced with animals and the code still seems to work, so why add 'elements' in the first place??? const secretMessage = animals.map (element => { return element[0]; }) // it took tvhe first of every letter and printed it console.log(secretMessage.join('')); const bigNumbers = [100, 200, 300, 400, 500]; // Create the smallNumbers array below const smallNumbers = bigNumbers.map( bigNumbers => { return bigNumbers/100; } ) //there is a way to replace bigNumber with element but why? const smallNumbers = bigNumbers.map( element => { return element/100; } ) console.log(secretMessage) console.log(smallNumbers)

i just want to know what is the purpose of adding elements when you can just use variables that were already created, is there a specific reason this is done?

and i am a newbie to coding so i hope my question is warranted and makes sense.

They are not already created. Replacing element with animals in the first map just creates a new local variable, animals, which has the same name as another variable. They are; however, in a different scope, which means that they aren’t the same variable.

I see… Thank you for your explanation

1 Like