Parameter & Argument

A parameter is a variable defined in a function declaration. An argument is the actual value passed to the function when it is called.

Parameters receive data.

Arguments provide the data.

Why they are important

Parameters and arguments allow functions to work with different data. Instead of writing separate functions for each value, you can pass values dynamically. This makes programs flexible and reusable.

How parameters work

When defining a function, you specify parameters inside parentheses.

 

Example:

function greet(name) { print("Hello " + name) }

Here:

  • name is a parameter
  • It acts as a placeholder for future input

How arguments work

When calling the function, you provide an argument.

greet("Alice")

Here:

  • "Alice" is the argument
  • It replaces the parameter name

So inside the function, name = "Alice".

Multiple parameters

Functions can have more than one parameter.

function add(a, b) { return a + b }

Calling it:

add(5, 3)

Here:

  • a and b are parameters
  • 5 and 3 are arguments

Key difference

  • Parameterdefined in the function
  • Argumentpassed when calling the function

Think of it like this:

A parameter is a labeled box.

An argument is the value placed inside the box.

Why learning this matters

Understanding parameters and arguments helps you:

  • Build dynamic functions
  • Pass data between parts of a program
  • Avoid hardcoding values
  • Write scalable code

Functions become powerful only when they accept input.

Related terms

Source

Simplified from general programming documentation and Wikipedia.

Nach oben scrollen