Suppose we had:
function add1 (x) {
return x+1;
}
Then we might call add1(5)
to get the value 6.
But with the brackets, rather than calling add1(5)
, we can replace it with (function (x) {return x+1;})(5)
. Basically this creates a function, and applies it to the value 5 immediately, whereas when we call add1(5)
, we are using a named/defined function.