5

I have this code in google tag manager:

<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','https://connect.facebook.net/en_US/fbevents.js');

fbq('init', '***********');
fbq('set','agent','tmgoogletagmanager', '***********');
fbq('track', "PageView");
</script>

I just wondered if anyone could tell me what '!function' is, or what it does? I have never seen it before and a google/duckduckgo search produced no results, that I could see.

Could it mean 'not a function'? Weird!

Leon Segal
  • 679
  • 7
  • 28
  • answer is here https://stackoverflow.com/questions/3755606/what-does-the-exclamation-mark-do-before-the-function – user1428716 Sep 20 '17 at 11:31

1 Answers1

7

It's a shorter method of writing an IIFE:

!function(){console.log('foo')}()

Is 1 character shorter than:

(function(){console.log('foo')})()
Cerbrus
  • 70,800
  • 18
  • 132
  • 147
  • yeah, I can see now that searching for '!' in SO produces no results! Thanks for the help. – Leon Segal Sep 20 '17 at 11:28
  • 2
    For things like this, search for "exclamation mark", for example. Search for the character's name, instead of the character. – Cerbrus Sep 20 '17 at 11:29