Named parameters enable you to specify an argument for a particular parameter by associating the argument with the parameter's name rather than with the parameter's position in the parameter list.
Questions tagged [named-parameters]
371 questions
420
votes
13 answers
Is there a way to provide named parameters in a function call in JavaScript?
C#, for example, allows using named parameters like so:
calculateBMI(70, height: 175);
I find this quite useful. How can I get a similar effect in JavaScript?
I've tried doing things like
myFunction({ param1: 70, param2: 175 });
function…

Robin Maben
- 22,194
- 16
- 64
- 99
330
votes
10 answers
Normal arguments vs. keyword arguments
How are "keyword arguments" different from regular arguments? Can't all arguments be passed as name=value instead of using positional syntax?

mk12
- 25,873
- 32
- 98
- 137
284
votes
7 answers
What is the difference between named and positional parameters in Dart?
Dart supports both named optional parameters and positional optional parameters. What are the differences between the two?
Also, how can you tell if an optional parameter was actually specified?

Seth Ladd
- 112,095
- 66
- 196
- 279
87
votes
2 answers
Python, default keyword arguments after variable length positional arguments
I thought I could use named parameters after variable-length positional parameters in a function call in Python 2, but I get a SyntaxError when importing a python class. I'm writing with the following "get" method, for example:
class Foo(object):
…

jkmacc
- 6,125
- 3
- 30
- 27
83
votes
5 answers
Named parameters in JDBC
Are there named parameters in JDBC instead of positional ones, like the @name, @city in the ADO.NET query below?
select * from customers where name=@name and city = @city

Fakrudeen
- 5,778
- 7
- 44
- 70
67
votes
6 answers
Why does a function call require the parameter name in Swift?
I have this Function in a class:
func multiply(factor1:Int, factor2:Int) -> Int{
return factor1 * factor2
}
I try to call the function using this:
var multResult = calculator.multiply(9834, 2321)
The problem is that the compiler wants it to…

67cherries
- 6,931
- 7
- 35
- 51
66
votes
6 answers
Named parameters
I have method
def test(String a, String b) { }
and I would like to call this with a dynamic parameter map.
I always though that
test(['1','2']); //valid call
and also
test([a:'1',b:'2']); //=> does not work
will work. but it doesn't. So I…

rdmueller
- 10,742
- 10
- 69
- 126
62
votes
3 answers
How to specify a JPA named parameter surrounded by wildcards?
How would I specify a JPA query like:
Query q =
em.createQuery(
"SELECT x FROM org.SomeTable x WHERE x.someString LIKE '%:someSymbol%'"
);
followed by:
q.setParameter("someSymbol", "someSubstring");
and not triggering…

Reuben Peter-Paul
- 1,550
- 3
- 15
- 25
57
votes
1 answer
Does C++ support named parameters?
Previously, I worked with Python. In Python I used named parameters (keyword argument) for function calls. The Wikipedia page about named parameters tells that C++ doesn't support it. Why doesn't C++ support named parameters? Will it support it in a…

Jobin
- 6,506
- 5
- 24
- 26
46
votes
5 answers
Forcing named arguments in C#
C# 4 introduced a feature called named arguments which is especially useful in scenarios like
int RegisterUser(string nameFirst, string nameLast, string nameMiddle, string email)
Is there a way to force using named arguments? Maybe some attribute…

UserControl
- 14,766
- 20
- 100
- 187
45
votes
0 answers
Is it possible to use named function parameters in PHP?
Is it possible in php like in python to have named function parameters? An example use case is:
function foo($username = "", $password = "", $timeout = 10) {
}
I want to override $timeout:
foo("", "", 3);
Ugly. I would much rather…

Justin
- 42,716
- 77
- 201
- 296
44
votes
6 answers
Typescript: Create class via constructor passing in named parameters?
I have a class where I have the constructor defined with 3 parameters which are all optional. I was hoping to be able to pass in named parameters so I don't need to pass in undefined.
constructor(year?: number,
month?: number,
…

Martin
- 23,844
- 55
- 201
- 327
41
votes
7 answers
Are Options and named default arguments like oil and water in a Scala API?
I'm working on a Scala API (for Twilio, by the way) where operations have a pretty large amount of parameters and many of these have sensible default values. To reduce typing and increase usability, I've decided to use case classes with named and…

DaGGeRRz
- 1,611
- 1
- 12
- 13
40
votes
6 answers
Kotlin: Can you use named arguments for varargs?
For example, you might have function with a complicated signature and varargs:
fun complicated(easy: Boolean = false, hard: Boolean = true, vararg numbers: Int)
It would make sense that you should be able to call this function like…

Jire
- 9,680
- 14
- 52
- 87
38
votes
16 answers
Does PHP allow named parameters so that optional arguments can be omitted from function calls?
Is it possible in PHP to specify a named optional parameter when calling a function/method, skipping the ones you don't want to specify (like in python)?
Something like:
function foo($a, $b = '', $c = '') {
// whatever
}
foo("hello",…

Stefano Borini
- 138,652
- 96
- 297
- 431