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

The Archive Base Latest Questions

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

Possible Duplicate: How do I make a default value for a parameter to a

  • 0

Possible Duplicate:
How do I make a default value for a parameter to a javascript function

in PHP:

function func($a = 10, $b = 20){
  // if func() is called with no arguments $a will be 10 and $ b  will be 20
}

How can you do this in JavaScript?

I get a error if I try to assign values in function arguments

missing ) after formal parameters

  • 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-23T09:30:20+00:00Added an answer on May 23, 2026 at 9:30 am

    In javascript you can call a function (even if it has parameters) without parameters.

    So you can add default values like this:

    function func(a, b){
       if (typeof(a)==='undefined') a = 10;
       if (typeof(b)==='undefined') b = 20;
    
       //your code
    }
    

    and then you can call it like func(); to use default parameters.

    Here’s a test:

    function func(a, b){
       if (typeof(a)==='undefined') a = 10;
       if (typeof(b)==='undefined') b = 20;
    
       alert("A: "+a+"\nB: "+b);
    }
    //testing
    func();
    func(80);
    func(100,200);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: passing an empty array as default value of optional parameter in c#
Possible Duplicate: Can I just make up attributes on my HTML tags? Hi, I
Possible Duplicate: How to make --no-ri --no-rdoc the default for gem install? I never
Possible Duplicate: How to make a redirect in PHP? Hi! How do i forward
Possible Duplicate: java PreparedStatement Can I make the prepared statement SELECT * FROM STUDENTS
Possible Duplicate: How do I make PDF the default export option for a Crystal
Possible Duplicate: How to make in Javascript full screen windows (stretching all over the
Possible Duplicate: Change color of selection How does this site manage to make text
Possible Duplicate: Make PHP execute and communicate with a Java application on a web
Possible Duplicate: PHP make if shorter I have an if statement that looks like

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.