I am almost new to JavaScript, and I am learning about the use of the anonymous function. I have written this piece of code and test it.
Code 1:
function build(something) {
return function(name) {
alert("Here is " + something + "\nHello " + name + "!");
};
}
After that I just removed the ;, but I am getting the same result. Code 2:
function build(something) {
return function(name) {
alert("Here is " + something + "\nHello " + name + "!");
}
}
The way I am calling the function is (for both cases):
var station = build("Station");
station();
Are they equivalent because in any case I am getting any error? If so, why is not needed the semicolon, and which one is mostly used?