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 8145337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:38:02+00:00 2026-06-06T13:38:02+00:00

Alright, I know what’s the difference between a FunctionDeclaration and a FunctionExpression . @

  • 0

Alright, I know what’s the difference between a FunctionDeclaration and a FunctionExpression. @CMS did a great job of explaining that. Till recently, I used to use the same syntax for creating lambda expressions and namespaces following Douglas Crockford’s example:

(function () {
    "use strict";
}());

He justifies this convention as follows:

When a function is to be invoked immediately, the entire invocation expression should be wrapped in parens so that it is clear that the value being produced is the result of the function and not the function itself.

This syntax is great for lambda expressions because they return a value. However, namespaces do not return a value. Hence I now prefer using the following syntax for namespaces instead (taken from the JavaScript Garden):

(function () {
    "use strict";
})();

The rationale behind the use of this syntax is given as follows:

( // evaluate the function inside the paranthesis
function() {}
) // and return the function object
() // call the result of the evaluation

Using this syntax for namespaces makes more sense to me because: this syntax separates the namespace and the invocation; and Douglas Crockford’s syntax expects the function to return a value.

However, when I pass this syntax through JSLint I get the an error stating “Move the invocation into the parens that contain the function.“. I don’t understand why it complains about this syntax. It’s a widely used and accepted syntax.

I plan on notifying Douglas Crockford about this problem. However, before I do so I would appreciate any feedback you may provide. Perhaps it’s better to simply stick with his syntax? Please explain your views.

  • 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-06T13:38:04+00:00Added an answer on June 6, 2026 at 1:38 pm

    In retrospect I believe Crockford’s views are simply dogma. He says:

    When a function is to be invoked immediately, the entire invocation expression should be wrapped in parens so that it is clear that the value being produced is the result of the function and not the function itself.

    Well my arguments is that when a function is being invoked immediately how is it not clear that the value being produced is the result of the function and not the function itself? Consider:

    The value being produced is the function:

    var f = function () {
        "use strict;"
    };
    

    The value being produced is the result of the function:

    var x = (function () {
        "use strict;"
    })();
    

    If you want the value being produced to be the function itself then simply don’t use parens. It doesn’t make sense to use them anyway.

    Understandably there are many programmers who would still wrap a function expression in parentheses before assigning it to a variable, or who would be a sadist and do something like this to confuse Doug:

    var x = function () {
        "use strict;"
    }();
    

    However how difficult is it to understand what’s going on? Perhaps in the last example you would need to scroll down several hundreds of lines of code to find out but a good programmer would save others the trouble and just wrap the function in parens; or if he’s a miser:

    var x = ~function () {
        "use strict;"
    }();
    

    Beside I wouldn’t even bother reading code written by someone who’s hell bent on making me curse him. Coming back to the question though the reason I really dislike Crockford’s syntax is because he’s grouping the function and invocation in a single parentheses. To me that’s equivalent to the following:

    var x = (f());
    
    function f() {
        "use strict;"
    }
    

    Obviously wrapping a function invocation in parens looks a little silly and redundant but that’s how I imagine it to be and it always irks me, but every man to his own way. Personally I think my syntax looks cleaner.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, I'm having a hard time explaining this, let me know if I should
Alright, I know that Scala allwos no aux cons type params. What if I
Alright, so this is something really basic, and I know that when someone tells
Alright, I wanna know why this code is working, I just realized that I
Alright I know that the .closest() have been discussed before, but I have been
Alright I know this is more than likely a amateur question but I have
Alright, i dont know how to explain it well.. but i have a switch
Alright, so I know about the Settings.Properties.Default.* Stuff, but thats not what im trying
Alright, so as you probably know, static inheritance is impossible in C#. I understand
Alright, I know this question has been asked before, but mine has a different

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.