Skip to content

I can’t get the value of the variable

I’m learning JavaScript and there is a question that I can’t understand:

Consider the given code:

let names = ['ahmed', 'karima', 'hamza','soad'];  
let modifiedNames = names.forEach(name => name+99);

The value of modifiedNames here will be?

I am printing the variable in the console but it gives me undefined?!

Thank you in advance.


You use Array.prototype.forEach which always returns undefined. Use if you want to map your array into a new one.

let names = ['ahmed', 'karima', 'hamza','soad'];  
let modifiedNames = => name+99);