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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:01:13+00:00 2026-06-13T19:01:13+00:00

I would like to have a function, which would be accessible to call it

  • 0

I would like to have a function, which would be accessible to call it by other functions and should self execute when declared.

Like:

function some(var_one, var_two)
{
    // do something
}(var_one, var_two); // declare and execute (doesn't work)

function add_pair()
{
    // do something
    some(James, Amber);
}

What is a proper syntax to do this?

  • 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-13T19:01:15+00:00Added an answer on June 13, 2026 at 7:01 pm

    You cannot invoke a function declaration. The pair of parentheses following the declaration will do nothing at all. You could do something like this:

    var some;
    (some = function (var_one, var_two) {
        console.log(var_one, var_two);
    })("a", "b");
    
    ​some("b", "c");​​​​
    

    The above example will log “a, b”, followed by “b, c”. But that looks a bit messy. You could just stick with what you have and call the function like normal:

    function some(var_one, var_two) {
        console.log(var_one, var_two);
    }
    some("a", "b");
    

    Update

    Note that by changing the function declaration to an expression (which is what happens in my first example above) you remove the ability to call the function before it appears to be declared in the source, since declarations are hoisted to the top of the scope in which they appear, and assignments happen in place. With a function declaration, the following example works perfectly:

    some("a", "b"); // Call it before it appears to be declared
    function some(var_one, var_two) {
        console.log(var_one, var_two);
    }
    

    I really can’t see any reason why you would need to combine the declaration and invocation into one.

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

Sidebar

Related Questions

I have written my own function, which in C would be declared like this,
My company would dearly like to have an iPhone app which, among other functions,
I would like to have a function that can wrap any other function call.
I would like a JavaScript function to have optional arguments which I set a
I have a pointer which points to a function. I would like to: if
I have this function that I would like to condense into some iterator. How
In my UserProfile model I would like to have a function which returns either
I have a function which performs calculations and I would like to be able
I would like to have a function which get start_day and end_day as two
I would like to have a mapping function that does this: public static void

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.