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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:44:30+00:00 2026-06-04T17:44:30+00:00

JavaScript has a Function constructor which produces an anonymous function: new Function() When passing

  • 0

JavaScript has a Function constructor which produces an anonymous function:

new Function()

When passing a function as an argument to Function, I get a syntax error:

new Function(function(){})

produces

SyntaxError: Unexpected token (

However, when I pass a number, all is fine:

new Function(10)

Why do I get a syntax error when passing a function to Function?

  • 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-04T17:44:31+00:00Added an answer on June 4, 2026 at 5:44 pm

    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function

    Considering all but the last arguments are argument names, I wouldn’t expect anything other than a string to work.

    I would imagine the syntax error is because of the way the JS engine you’re using internally tries to convert the function to a string. I’m actually surprised it doesn’t choke on the 10.

    Also, I suspect you’re doing this just out of curiosity, but if you’re not, I suggest you not use Function in code you can control. There’s not really a reason to use Function unless you need to take a string and make a function out of it at run time.

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

Sidebar

Related Questions

I want to create a constructor function in javascript, which has a .prototype property
JavaScript has lexical scoping which means that non-local variables accessed from within a function
Javascript has a poorly constructed but convenient arguments variable inside every function, such that
I have some third-party Javascript that has statements like this: FOO = function() {
I´ve got a star image as <img> . This image has a javascript function,
I'm calling the JavaScript function onsubmit of form but form has submit before finished
I need to create a javascript function that checks if it has been a
This has me stumped. The follow code returns ,,,,,,: <script type=text/javascript> $(function() { $('#listB').sortable({
Today I saw a JavaScript syntax (when invoking a function) that is unfamiliar to
I have a simple JavaScript file that has three jQuery $document.ready functions. All three

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.