Peter
Peter

Reputation: 7804

Javascript in bootstrap api...what does the ! mean

At the beginning of the bootstrap.js code file they have this

!function($) {

what does it mean?

Upvotes: 1

Views: 255

Answers (1)

Michael Manoochehri
Michael Manoochehri

Reputation: 7877

If you code this: function something() {something}, it's a declaration of a function, but it does not invoke the function (you'd have to run something() later on).

So, to actually invoke the function, you need to do something like (function(){})(); ... "!function($) {}" is sort of an alternative to the wrapping the entire function in parens. The exclamation mark syntax is a shortcut to writing that. "!" turns the line into an expression that returns true.

Upvotes: 2

Related Questions