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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:34:53+00:00 2026-05-30T09:34:53+00:00

All, I use JSLint to validate my JS files. In my most recent project,

  • 0

All,

I use JSLint to validate my JS files. In my most recent project, I am using the following format to set default values for a number of JavaScript functions (further detailed here):

function(a, b, option) {
    option = arguments.length > 2 ? option : "some default value";
    // ...
}

This however causes the latest build of JSLint to produce the following error:

"Do not mutate parameter 'option' when using 'arguments'."

I am aware that using the more common method for assigning defaults (i.e., option = option || {};) supresses the error; however, this will produce incorrect behaviour if I intend to pass a falsey value to option.

Is the only solution to this issue to introduce a new variable? e.g.:

var option2 = arguments.length > 2 ? option : "some default value";
  • 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-30T09:34:54+00:00Added an answer on May 30, 2026 at 9:34 am

    I guess JSLint warns you since you try to modify one of the input arguments by using a check with the arguments keyword. JSHint, however, does give me any warning when trying your code.

    A solution to your problem would be to check if option is defined or not, that way you go around the problem with sending in falsy values:

    function(a, b, option) {
        if(typeof option === "undefined") {
            option = "some default value"; 
        }
        // ...
    }
    

    If you find that it is cumbersome to write this typeof check everytime, create an isDef function:

    function isDef(param) {
        return typeof param !== "undefined";
    }
    function(a, b, option) {
        option = isDef(option) ? option : "some default value"; 
        // ...
    }
    

    // Simon A.

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

Sidebar

Related Questions

Why all use binary files, if all can use XML ?
I'm using TortoiseGit on Windows XP. My team all use a central svn server
Normally we all do use using System.Linq; and using System.Data.Linq; for example on the
I want to use all the photos in a Flickr set and in order
I've seen all the howtos about how you can set a ModelMultipleChoiceField to use
I have like 50 different php files which all use the mail function. After
I have a folder with many LaTeX files that all use the same custom
Like most people I use SWFObject to embed Flash (swf) files to my Web
I have developed over 50 sites that all use the exact same files other
When you have multiple projects that all use the same set of JAR libraries,

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.