I am relatively new to JavaScript and currently exploring the concept of anonymous functions. I created the following code snippet to test my understanding:
Code 1:
function build(something) {
return function(name) {
alert("Here is " + something + "\nHello " + name + "!");
};
}
Subsequently, I decided to remove the semicolon and compare the results:
Code 2:
function build(something) {
return function(name) {
alert("Here is " + something + "\nHello " + name + "!");
}
}
I am invoking the function in both cases as follows:
var station = build("Station");
station();
Although I am not encountering any errors, I am curious if both approaches are equivalent. Additionally, I am wondering why the semicolon is not necessary and which syntax is more commonly used in practice.