Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8367409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:09:01+00:00 2026-06-09T13:09:01+00:00

Possible Duplicate: What does the exclamation mark do before the function? If you look

  • 0

Possible Duplicate:
What does the exclamation mark do before the function?

If you look at the source code for KnockoutJS 2.1.0 you will see a code structure like this start on line 7:

!function(factory) { ... }(factoryDefinition);

The not operator causes this expression to evaluate to true rather than undefined, but why bother?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:09:02+00:00Added an answer on June 9, 2026 at 1:09 pm

    This is a concise way to form an immediately executed function expression.

    Traditionally, people have used these two forms

    (function(){ }()); // Recommended by Crockford
    (function(){ })(); // What most people use
    

    If you try to just use

    function(){ }(); // Syntax error
    

    it will be a syntax error, because it is interpreted as a function declaration rather than an expression. This is why you would need to wrap the function in parentheses.

    But if you put a unary operator before the function declaration, you don’t have to add a cosing parentheses, and it chops off one character of the code, which is a (very) tiny performance benefit. There are several unary operators that can be used for this same purpose

    !function(){ }();
    ~function(){ }(); 
    -function(){ }(); 
    +function(){ }(); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What does the exclamation mark do before the function? What's the point
Possible Duplicate: What does the exclamation mark do before the function? I saw a
Possible Duplicate: What does the question mark and the colon (?: ternary operator) mean
Possible Duplicate: What does (function($) {})(jQuery); mean? For the function (function($){})(), I've seen it
Possible Duplicate: Does every thread need its own autorelease pool? I would like to
Possible Duplicate: When does invoking a member function on a null instance result in
Possible Duplicate: Why does simple C code receive segmentation fault? I am working in
Possible Duplicate: What does this “(function(){});”, a function inside brackets, mean in javascript ?
Possible Duplicate: Does the Facebook 'like' have a limit? Facebook like button updates the
Possible Duplicate: Why does C# not provide the C++ style ‘friend’ keyword? I'd like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.