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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:59:23+00:00 2026-06-14T20:59:23+00:00

I was taking a look at the source code of Uglify-js where I noticed

  • 0

I was taking a look at the source code of Uglify-js where I noticed something interesting. In bin/uglifyjs (ref) a couple of functions are defined like this:

//syntax A
var defsym = function(sym) {
  ...
},
defval = function(v) {
  ...
};

Considering that Uglify-js is written by professionals and is used in many products like JQuery, I don’t understand why the code isn’t written like this:

//syntax B
var defsym = function(sym) {
  ...
};
var defval = function(v) {
  ...
};

This will make it more clear that these are two local variables. Or how about this:

//syntax C
function defsym(sym) {
  ...
}
function defval(v) {
  ...
}

This one makes the defsym and defval functions be available through the entire scope of the mother function.

Why would they choose the first syntax? Why not the other syntaxes?

  • 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-14T20:59:24+00:00Added an answer on June 14, 2026 at 8:59 pm

    Why wouldn’t they use Syntax B? Because it requires more characters.

    Why wouldn’t they use Syntax C? Because its meaning is not entirely the same. Function declarations are not exactly the same as function expressions.


    Now I see that the assignments are taking place in a try/catch, which means that they are in a block.

    It’s invalid to declare functions in a block (even though some implementations allow it).

     // Invalid
    try {
        function defsym(sym) {
            // ...
        }
        // ...
    } catch(e) {
        // ...
    }
    

     // Valid
    try {
        var defsym = function(sym) {
            // ... 
        },
        // ...
    } catch(e) {
        // ...
    }
    

    So this explains why they didn’t choose Syntax C.

    Also, “strict mode” will absolutely prohibit such invalid declarations by throwing an error.

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

Sidebar

Related Questions

I was taking a look through some open-source C++ code and I noticed a
I was taking a look on the jquery.validate plugin source code , to check
I'm taking a look now to XtraReports reporting tool and there's something that I
Taking a look at my question HERE , I now want to return the
After taking a look at this SO question and doing my own research, it
Thanks for taking a look at this. The issue has to do with the
I was taking a look at Star Schema Benchmark and then I was thinking
I'm now taking a look at the PocketC powerful tool, but there is an
I'm taking a look at some random Icecast playlists (available here: http://dir.xiph.org/index.php ) and
I am finalizing one of my projects and taking a look over the whole

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.