I thought before that function expression can be any function that is store in some variable. For example, this is function expression, because function is stored in func
variable.
let func = function() {
console.log(5);
};
And here's function expression, because callback function is stored in function's paremeter callback
.
function func(callback) {
callback();
};
func(function() {
console.log(5);
});
//That's what I mean:
//let callback = function() {...}
But... recently I've found out that this callback function can also be considered as function expression. Why? This function isn't stored in some variable.
let arr = [18, 50];
let obj = {
name: 'Karina',
};
arr.forEach(function func(value) {
console.log(`${this.name} is ${value} years old`);
}, obj);
So, my question is...What exactly make function function expression?