I'm practicing the forEach() construct on simple letter array. I want to convert letters to uppercase and print them to the console. So I've made it work, when I put the console.log() inside the callback function. But why on earth it isn't possible to put the console.log() outside the callback function. It gives an undefined error
This works:
var letters = [ "a","b","c"];
var capitalize = function (element,index,array) {
console.log(element.toUpperCase());
};
letters.forEach(capitalize);
this doesn't work: (it gives undefined)
var letters = [ "a","b","c"];
var capitalize = function (element,index,array) {
return element.toUpperCase();
};
console.log(letters.forEach(capitalize));
.mapor explicitly insert areturnstatement. E.g.return element.toUpperCase();