-5

Can anyone explain to me how this works / what it does (more specifically the ( before the function) as I don't understand why the function after inArray has a ( around it?

function geoip(g){window.top.location.href=inArray(g.country_code,filter)?targetVisitorsUrl:allVisitorsUrl}
    function inArray(r,n){for(var t=n.length,e=0;t>e;e++)if(n[e]==r)return!0;return!1}
    (function(g,e,o,i,p){i=g.createElement(e),p=g.getElementsByTagName(e)[0];i.async=0;i.src=o;p.parentNode.insertBefore(i,p)})(document,'script','https://api.ipdata.co/?api-key=test&callback=geoip');

Thank you

Stuart
  • 45
  • 8
  • Googling for “javascript function in parentheses” or similar could have easily lead you to this answer, https://stackoverflow.com/q/440739/10283047 – misorude Nov 16 '18 at 10:37

1 Answers1

1

You are asking what IIFE is.

IIFE stands for Immediately Invoked Function Expression. The disambiguation is self-descriptive. It's just a function that is invoked immediately:

(function () { alert( ' immediate alert! ' ) })()
Nurbol Alpysbayev
  • 19,522
  • 3
  • 54
  • 89