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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:43:26+00:00 2026-05-27T13:43:26+00:00

With Express / Connect I can set up an middleware function in either of

  • 0

With Express / Connect I can set up an middleware function in either of the formats:

function(req, res, next) // first argument will be a request

Or

function(err, req, res, next) // first argument will be an error

Stepping back from Express, Connect, to basic JavaScript: I don’t understand is how this is possible to have an optional first argument?

How can express know that my function will accept an err object first? I thought to make this possible the structure would have to be like the following:

function(req, res, next, err)

Am I missing something basic here? Is it possible to query how many arguments a function is expecting?

The middleware function is passed to express, so the arguments variable is not valid. although length is correct… I think I have figured it out, would be good to have confirmation to whether this is the case. Example below:

var fn;

fn = function (one, two) {};
console.log(fn.length); // 2

fn = function (one, two, three) {};
console.log(fn.length); // 3
  • 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-27T13:43:26+00:00Added an answer on May 27, 2026 at 1:43 pm

    I think I have figured it out, would be good to have confirmation to whether this is the case

    var fn;
    
    fn = function (one, two) {};
    console.log(fn.length); // 2
    
    fn = function (one, two, three) {};
    console.log(fn.length); // 3
    

    Yes, that’s correct. The length property of a Function instance is the number of formal parameters (declared arguments) it has. This is hidden away in Section 13.2 of the spec, steps 14 and 15.

    So it’s quite easy for the code calling the function to check fn.length and pass it the optional first argument, or not, depending on that. This does mean, of course, that it’s entirely possible to write a function that would handle the four-argument version, but fools the framework by using arguments rather than formal parameters. So you wouldn’t do that. 🙂

    (Apologies for misreading your question the first time.)

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

Sidebar

Related Questions

From Visual Studio 2010 I can connect to my SQL Server Express 2005 instance
I'm using Express.js to create a server to which I can connect using web
I'm trying to connect to a MS SQL Server 2005 Express database that is
I'm trying to connect a C# application (using Visual C# 2008 Express Edition) to
Env.: Vista SP1, SQL Server Express 2005 I'm able to connect to my localhost
I can connect to remote SQL Server database and I want to create a
(very newbie question, please help if you can) how do i connect visual web
Visual Studio 2005 I connect with SQL Server Express edition with SQL Server Management
I am having sql server express edition local database in app_data folder. How can
I'm using node.js with Express and connect-auth to authenticate users. This is the verification

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.