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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:14:53+00:00 2026-06-18T01:14:53+00:00

I just spend long time digging through callbacks in promises wondering why some callbacks

  • 0

I just spend long time digging through callbacks in promises wondering why some callbacks are not called. In the end problem was with incorrect declaration, instead of

       Promise.when(null).then(function () {
            var p = new Promise();
            p.fail(new Error("some message"));
            return p;
        }).then(function () {
            console.log("success");
        }, function (err) {
            console.log("failure");
        });

I did

       Promise.when(null).then(function () {
            var p = new Promise();
            p.fail(new Error("some message"));
            return p;
        }).then(function () {
            console.log("success");
        }), function (err) {
            console.log("failure");
        };

Regardless of Promise implementation details it boils down to one thing:

function(){};//throws SyntaxError
"something valid, or function call", function(){};//no error

I would like someone to explain this to me. Why first is throwing SyntaxError while latter is valid (at least in browser console)? It seems to declare anonymous function.
Same thing happens when I try

eval("function(){};//throws SyntaxError")
eval("'lala',function(){};//no error")

So can someone explain me why first is not valid while latter is ?

  • 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-18T01:14:55+00:00Added an answer on June 18, 2026 at 1:14 am

    A statement that begins with the keyword “function” must be a valid function declaration statement. That requires a name for the function.

    In an expression (or expression statement), that rule is different; no name is necessary because the function acts as a value in that context. No name is required then.

    Thus this:

    function myFunction() {
      // ...
    }
    

    is a function declaration statement. This:

    5 + function() {};
    

    is an expression statement (a silly one, but JavaScript is ok with that). Similarly, your example that results in no error is an expression with the comma operator:

    "lala", function() {};
    

    The keyword “function” does not appear at the beginning of either of those two expressions, so the parser does not insist on a name for the function.

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

Sidebar

Related Questions

Have spend quite some time to learn Sencha touch, just like an evaluation about
(DISCLAIMER: I'm not a programmer, I spend my time on serverfault, I'm just a
I've just spent a long time trying to figure out why my Javascript for()
(Sorry if this is a dupe) I've just spent a long time trying to
I just spent a long time breaking my teeth on why this code was
After a long time learning python I finally managed to make some breakthroughs: I'm
Again me. I was using for a bit long time KohanaPHP and just can't
I've just spent an entirely too long amount of time screaming my head off
I just spent a very long time debugging an issue in python, using the
I just spent way too long trying to diagnose why, in the following snippet

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.