Reputation: 13
let f = function(x) {
alert(x)
}
(function() {
f(1)
}())
Why is this code throwing an error? At first, I thought the problem was connected with the incorrect syntax of the IIFE but then I learned that this syntax is also appropriate
Upvotes: 1
Views: 44
Reputation: 386604
This is the one of the rare cases where a semicolon is necessary to separate the function expression from the calling with the following parentheses.
let f = function(x) {
alert(x)
}; // <-------------------
(function() {
f(1)
}())
Upvotes: 5