1

I am working on a project in javascript and while going through design pattern concepts came across following point. I have a sample code as below:

 window.customfun = (function(){}())

Here i have two questions: 1) Can we not simply define a global function as below:

customfun = (function(){}())

2) (function(){}()) is an anonymous function with its own evaluation environment but i have learnt that to be implemented as : (funtion(){})()see the position of parentheses around couple of parentheses. I found that both are working so i wanted to know if there is any difference between them?

flamelite
  • 2,324
  • 2
  • 19
  • 41

1 Answers1

1
  1. Sure, you can define global functions

  2. No, there is actually no difference.

Is there a difference: (1+(1)) === (1) + (1) ?

webdeb
  • 12,584
  • 5
  • 25
  • 44