How are these two pieces of code different from each other?
var a = (function() {//code})();
and var a = function () {//code}();
`
I tried to use both the ways in my code and they both worked well. So, it got me confusing as to why we wrap the function declaration of an IIFE in parenthesis? Here is an example where i use both the ways for the same purpose:
let a = (function () {
let count = 0;
return {
increment : function () {
console.log(++count);
}
}
})();
a.increment();
a.increment();
a.increment();
and
let a = (function () {
let count = 0;
return {
increment : function () {
console.log(++count);
}
}
})();
a.increment();
a.increment();
a.increment();