Hello I am a newbie I have a one question

const bigNumbers = [100, 200, 300, 400, 500];

// Create the smallNumbers array below
const smallNumbers = bigNumbers.map(num => num/100);

console.log(smallNumbers)

that is a correct way

I have a few test for understand more

so I tried

const bigNumbers = [100, 200, 300, 400, 500];

// Create the smallNumbers array below
const smallNumbers = bigNumbers.map(num => {num/100});

console.log(smallNumbers)

like this in that case the value of smallNumbers printed by undefined

why it happend like this? stupid question but I donโ€™t get it

Hey @byteblaster11428, welcome to the forums!

This happens because you have surrounded num/100 in curly braces.

2 Likes

To elaborate on @stevencopelandโ€™s answer, when curly braces are used in an arrow function there is no implicit return so the return keyword must be present.

a = [100, 200, 300, 400, 500];

b = a.map(x => x / 100)

OR

b = a.map(x => {
    return x / 100
}
4 Likes