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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:53:40+00:00 2026-06-10T23:53:40+00:00

If I try to execute a script whose only source line is an object:

  • 0

If I try to execute a script whose only source line is an object:

{prop:'value'}

it parses fine (in both V8 and UglifyJS). Similarly I can put a string or number on its own as source code and there is no syntax error reported.

However, both V8 and UglifyJS complain about this on its own:

function(){}

I get Uncaught SyntaxError: Unexpected token (.

Why does this break when the object in the first example is fine? Aren’t functions just objects in javascript?

I realise declaring an anonymous function without executing it won’t do anything; that’s not the question. I want to know why it causes a parse error.

  • 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-10T23:53:41+00:00Added an answer on June 10, 2026 at 11:53 pm

    From the ECMAScript spec, section 12.4 on expression statements:

    Note that an ExpressionStatement cannot start with an opening curly brace because that might make it ambiguous with a Block. Also, an ExpressionStatement cannot start with the function keyword because that might make it ambiguous with a FunctionDeclaration.

    Although functions are just objects, remember that you can declare functions on their own without really making use of their objects in expressions. That’s where the ambiguity lies. Granted, you can never declare an anonymous function on its own (as you won’t be able to reference it anyway), but as I can’t find anything in the spec that distinguishes between anonymous function and named function declarations, I suspect this applies to both.

    In order to resolve the ambiguity you need to wrap it in parentheses, so it will always be treated as an expression:

    (function(){})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

when I try to execute command like this (from a command-line or Perl script
I try to execute a simple SQL query in a shell script but I
When I try to execute script PutEnv(TNS_ADMIN='C:\\Programy\\OracleDeveloper10g\\NETWORK\\ADMIN\\'); $conn = oci_connect(user, pass, dbstring); if (!$conn)
I try to execute a shell script during the build in Jenkins but i
When I try to execute a package which uses the Scripting Component object I
I want to execute a bash script with ssh but when I try this
I want to try to use a command line script with my python application.
When I try to execute the below class using ICriteria, if (_userGroupId > 0
When I try to execute this statement in Oracle SQL Developer 2.1 a dialog
When I try to execute my code, I'm getting an error dialog: 'Show Disassembly'

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.