Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
The Machine
10,221 PointsIs there a difference between '+' and '!' for JavaScript self-calling anonymous function modular pattern?
(from Track "The Module Pattern in JavaScript")
4 Answers
Ryan Zimmerman
3,854 PointsHi Brac,
Can you give more context?
Ryan Zimmerman
3,854 PointsYeah, my answer would be no.
Best practice is to ;
Between that, module.exports and great server side bundlers you shouldn't have a problem.
The Machine
10,221 PointsThanks for the reply Ryan. To clarify -- you state there is no functionality difference between the three code examples above AND you would suggest sticking with the first, more verbose code example?
Ryan Zimmerman
3,854 PointsYes
Ryan Zimmerman
3,854 PointsThe Machine
10,221 PointsThanks Ryan!
The Machine
10,221 PointsThe Machine
10,221 PointsRegarding wrapping all code in a single JavaScript file with a self-executing anonymous function, i.e.
In multiple files, so
;is needed at beginning as well so that file inclusion is not order dependent. Can simplify to:OR
Reference first 5 minutes of: https://teamtreehouse.com/library/the-module-pattern-in-javascript-2
My question is -- is there a functional difference between using the
+and!, or is it just personal preference?Thanks, Brac