MDN uses the second code I have provided and it runs fine but throws an error at the end. Why did they end the anonymous function with a semicolon? Is it ok to have an anonymous function if its not going to be in a function expression? Functions aren't supposed to end in semicolons if they aren't function expressions.
function makeAdder(x) {
return function(y) {
return x + y;
}
}
var add5 = makeAdder(5);
var add10 = makeAdder(10);
console.log(add5(2)); // 7
console.log(add10(2)); // 12
versus
function makeAdder(x) {
return function(y) {
return x + y;
};
}
var add5 = makeAdder(5);
var add10 = makeAdder(10);
console.log(add5(2)); // 7
console.log(add10(2)); // 12