0

Looking at the contents of a transpiled JavaScript file, from a site which appears to use MeteorJS, I saw some odd syntax with which I was unfamiliar. I didn't find any search results which explained what was going on.

!function(){var n = Package.meteor.Meteor, e=Package.meteor.global...

This appears many times and references a number of libraries (meteor-babel-helpers, for example), so I can guess that this has something to do with loading dependencies, but what does this accomplish?

In the spirit of testing, I opened up a console and prepended the ! to a simple function, and as expected it simply coerces the function to a false value. Why would I ever use this? Is it a way to force the function to be executed?

Miles Grimes
  • 432
  • 2
  • 16
  • It is one of the way to immediately invoke a function – brk Jun 19 '18 at 15:56
  • Can you show more of the code or link to it? The code may be minified. Minified code !== code written with best practices in mind. – zero298 Jun 19 '18 at 15:59
  • 1
    @zero298 This has been correctly marked as a dupiocate, I simply didn't find the relevant previous question. – Miles Grimes Jun 19 '18 at 16:45

0 Answers0