I'm sorry if my question seems silly but I'm still not clear about the difference of various modes of calling a function. EXAMPLE:
function a(name) {
console.log("hello " + name);
}
// Case 1:
a("John");
// Case 2:
console.log(a("John"));
// Case 3:
var b = a;
console.log(b("John"));
ps: Also I haven't grasp the need of a return
statement(except that stops the function after being executed). Is it not the same if i use an alert()
, console.log()
or another function that can fulfil the same purpose?