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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:08:19+00:00 2026-05-24T12:08:19+00:00

Is the script below in correct form of JavaScript? function foo(){ return function(x){ alert(x)

  • 0

Is the script below in correct form of JavaScript?

function foo(){
    return function(x){
        alert(x)
    }
}
foo()("bar");
    ↑   ↑
   There are 2 parenthesis.

It works but I don’t know if it is in a correct form.
If yes, then is that mean this is also correct?

function foo(){
    return function(){
        return function(){
            return function(){
                return function(x){
                    alert(x)
                }
            }
        }
    }
}
foo()()()()("?!?!?!");

It looks strange to me but it does work…

  • 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-24T12:08:19+00:00Added an answer on May 24, 2026 at 12:08 pm

    The order of function calls is shown by adding parameters:-

    function foo(a){
        var A=a;
        return function(a){
            A+=a;
            return function(a){
                A+=a; 
                return function(a){
                    A+=a;
                    return function(a){
                        A+=a;
                        alert(A)
                    }
                }
            }
        }
    };
    foo('a')('b')('c')('d')('e');// displays abcde
    

    You could make the function return itself so it can be repeatedly called, eg

    var foo = (function(){
        var v=1;
        return function f(x){
            return x==undefined?v: (v*=x, f);
        }
    })();
    foo.toString=function(){
    return foo();
    };
    alert(foo(1)(2)(3)(4)(5)(6)(7)(8)(9)(10));
    

    Nesting is usually to keep variables private, eg

    var factorial=(function(n){
        var precog = [1,1];
        var factorial= function f(y){
            if(precog[y]==undefined){
                precog[y]=y*f(y-1);
            }
            return precog[y];
        };
        factorial(n);// initialise some precogs
        return factorial;
    })(100); 
    

    Because precog is declared in the brackets its values, calculated internally by the factorial function, cannot be messed about with.

    The function assigned to the variable is called as normal:-

    factorial(3);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My script: <script language=JavaScript> function submitform() { document.playsong.submit(); } </script> Submits the below form:
I have two problems in my current .htaccess. The script below works but has
In the following example: <html> <head> <SCRIPT language=JavaScript> function checkcheckboxElem(checkboxElem) { alert (checkboxElem +
Is there a difference between the two examples below for beginning a Perl script?
I have example of code below. <script type=text/javascript src=assets/scripts/somescript.php>. </script> So, will my browser
This form works in Safari. In IE, it mostly works, but I get an
Can anyone tell me why when I ran a script with the below contents
Want to update page after jeditable (using gem on_the_spot) has been updated. Below works
Is it possible to modify the script below so that the value of each
Possible Duplicate: JavaScript: string contains In the below code I have to check whether

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.