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

  • SEARCH
  • Home
  • 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 7034351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:10:31+00:00 2026-05-28T01:10:31+00:00

I know this is silly, but there’s any difference between this: (function() { var

  • 0

I know this is silly, but there’s any difference between this:

(function() {  
    var foo = 'bar';  
})();

and this?

(function() {  
    var foo = 'bar';  
}());

JSLint tells us to Move the invocation into the parens that contain the function, but I see no need to.

Edit: The answers are too cool. ~function, the JSHint alternative along with jQuery’s preference for (/***/)(); and Crockford’s explanation! I thought I was going to just get a “they’re the same thing” kind of answer.
You guys decide the best one through upvotes and I tick it.

  • 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-05-28T01:10:32+00:00Added an answer on May 28, 2026 at 1:10 am

    There’s no difference. Both are valid ways to get the JavaScript parser to treat your function as an expression instead of a declaration.

    Note that + and ! will also work, and are sometimes used by minifiers to save a character of size:

    +function() {  
        var foo = 'bar';  
    }();
    
    !function() {  
        var foo = 'bar';  
    }();
    

    EDIT

    As @copy points out, for completeness, ~ and - will also work.

    -function() {  
        var foo = 'bar';  
    }();
    
    ~function() {  
        var foo = 'bar';  
    }();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know how silly this may sound, but is there a way to attach
Guys I know this question is silly but just to make sure: Having in
Ok so this maybe a simple/silly question but I don't know so here goes:
I know the question sounds silly, but consider this: I have an array of
Now this may seem like a silly question, but I need to know how
This may be a silly question I don't know. Is there a way to
Is there any function in java like toString() to print a String array? This
I know this is silly question, but i am just stuck with this: 1.I
This seems really silly but; How can I know which version of ASP.net MVC
I know this may be a silly question for experienced coders. But I have

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.