It is possible to use default parameter value its same function name

navedhn

I would like to know if it is possible to use the function itself in its default parameter.

function somename(a,b=somename()){
    return a+b;
}
somename(10);
CertainPerformance

Sure you can, as long as you design the logic such that it doesn't enter an endless recursive loop. For example:

function somename(a, b = somename(3, 5)) {
  return a + b;
}
console.log(somename(10));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why can't use let to declare a variable using the same name as one function parameter, even the parameter get set default value?

Is there a way to make a Powershell function ignore a default parameter's value if its parameter set is not in use?

In Swift, is it possible to use a parameter value in a default parameter value?

Why can't a default parameter and function parameter have the same name?

Which default value to use for an optional parameter that is a function

Using the length of a parameter array as the default value of another parameter of the same function

Is it possible to have a single parameter receive its value conditionally in a step function?

Sending default parameter as null and use default value set in function

Laravel model use default value instead of attribute value with the same name

Is it possible to provide a default value for a generic function's parameter?

Default value for function as parameter

Is it possible to use a string value to specify the name of a parameter's string accessor?

Variable with same name inside function changes the value of the passed parameter

Cannot use let to define a variable with the same name of function's parameter

Use initializer list as default value for function/method parameter

Is It Possible To Set Default Parameter Value On A Rest Parameter

Default value with the same name as property

How to use the value of a parameter as a property name in the return type for a function in TypeScript?

Can I use the value of a variable as a parameter name for a function?

Use variable name, not its value

get function parameter with default value

JavaScript function default parameter value

How to call a function by its name, passed as parameter?

How to pass as a parameter the name of a function and its parameters?

How to pass reference of a class parameter value to a function default argument value within the same class

Is having the first JavaScript parameter with default value possible?

Is it possible to override the default value of a parameter in Jenkins?

possible to use #ifndef on a function name?

How to make "dplyr select" to use the value of the character parameter instead of its name as a literal?