Questions tagged [arguments]

An argument is a value passed to a function, procedure, or command line program. This also refers to the Array-like `arguments` object in JavaScript.

An argument is a value passed to a function, procedure, or program. It is often used interchangeably with the word "parameter", which also has more specific definitions. Usually "argument", or "actual parameter" (as opposed to "formal parameter") is the value of the parameter used within the called routine.

In other words, parameters are used in procedure definitions, and arguments are used in procedure calls.

arguments can also refer to the Array-like object in JavaScript that is available inside functions, this object can be used to access all of the function's arguments regardless of the function's signature.

9862 questions
4722
votes
20 answers

Reference — What does this symbol mean in PHP?

What is this? This is a collection of questions that come up every now and then about syntax in PHP. This is also a Community Wiki, so everyone is invited to participate in maintaining this list. Why is this? It used to be hard to find questions…
Gordon
  • 296,205
  • 68
  • 508
  • 534
2606
votes
31 answers

How do I pass command line arguments to a Node.js program?

I have a web server written in Node.js and I would like to launch with a specific folder. I'm not sure how to access arguments in JavaScript. I'm running node like this: $ node server.js folder here server.js is my server code. Node.js help says…
milkplus
  • 28,909
  • 7
  • 26
  • 31
2489
votes
28 answers

Set a default parameter value for a JavaScript function

I would like a JavaScript function to have optional arguments which I set a default on, which get used if the value isn't defined (and ignored if the value is passed). In Ruby you can do it like this: def read_file(file, delete_after = false) #…
Tilendor
  • 45,619
  • 15
  • 48
  • 58
2162
votes
37 answers

How do I parse command line arguments in Bash?

Say, I have a script that gets called with this line: ./myscript -vfd ./foo/bar/someFile -o /fizz/someOtherFile or this one: ./myscript -v -f -d -o /fizz/someOtherFile ./foo/bar/someFile What's the accepted way of parsing this such that in each…
Lawrence Johnston
  • 58,608
  • 40
  • 113
  • 181
1237
votes
18 answers

How can I pass arguments to a batch file?

I need to pass an ID and a password to a batch file at the time of running rather than hardcoding them into the file. Here's what the command line looks like: test.cmd admin P@55w0rd > test-log.txt
Keng
  • 48,571
  • 31
  • 77
  • 109
1128
votes
7 answers

Passing parameters to a Bash function

I am trying to search how to pass parameters in a Bash function, but what comes up is always how to pass parameter from the command line. I would like to pass parameters within my script. I tried: myBackupFunction("..", "...", "xx") function…
stivlo
  • 77,013
  • 31
  • 135
  • 193
836
votes
28 answers

Is there a better way to do optional function parameters in JavaScript?

I've always handled optional parameters in JavaScript like this: function myFunc(requiredArg, optionalArg){ optionalArg = optionalArg || 'defaultValue'; // Do stuff } Is there a better way to do it? Are there any cases where using || like that…
Mark Biek
  • 135,050
  • 52
  • 150
  • 195
814
votes
35 answers

What's the difference between an argument and a parameter?

When verbally talking about methods, I'm never sure whether to use the word argument or parameter or something else. Either way the other people know what I mean, but what's correct, and what's the history of the terms? I'm a C# programmer, but I…
rohancragg
  • 4,904
  • 5
  • 32
  • 44
646
votes
7 answers

Which exception should I raise on bad/illegal argument combinations in Python?

I was wondering about the best practices for indicating invalid argument combinations in Python. I've come across a few situations where you have a function like so: def import_to_orm(name, save=False, recurse=False): """ :param name: Name…
cdleary
  • 63,281
  • 49
  • 155
  • 190
625
votes
1 answer

"Parameter" vs "Argument"

I got parameter and argument kind of mixed up and did not really pay attention to when to use one and when to use the other. Can you please tell me?
dummy
571
votes
11 answers

JavaScript variable number of arguments to function

Is there a way to allow "unlimited" vars for a function in JavaScript? Example: load(var1, var2, var3, var4, var5, etc...) load(var1)
Timo
  • 6,427
  • 6
  • 22
  • 25
553
votes
8 answers

How to write a bash script that takes optional input arguments?

I want my script to be able to take an optional input, e.g. currently my script is #!/bin/bash somecommand foo but I would like it to say: #!/bin/bash somecommand [ if $1 exists, $1, else, foo ]
Abe
  • 10,626
  • 12
  • 42
  • 70
445
votes
21 answers

How can I convert the "arguments" object to an array in JavaScript?

The arguments object in JavaScript is an odd wart—it acts just like an array in most situations, but it's not actually an array object. Since it's really something else entirely, it doesn't have the useful functions from Array.prototype like…
Andrew Coleson
  • 9,452
  • 7
  • 28
  • 30
431
votes
7 answers

How do I pass a unique_ptr argument to a constructor or a function?

I'm new to move semantics in C++11 and I don't know very well how to handle unique_ptr parameters in constructors or functions. Consider this class referencing itself: #include class Base { public: typedef unique_ptr UPtr; …
codablank1
  • 5,425
  • 4
  • 17
  • 26
355
votes
10 answers

TypeError: method() takes 1 positional argument but 2 were given

If I have a class... class MyClass: def method(arg): print(arg) ...which I use to create an object... my_object = MyClass() ...on which I call method("foo") like so... >>> my_object.method("foo") Traceback (most recent call…
Zero Piraeus
  • 47,176
  • 24
  • 135
  • 148
1
2 3
99 100