Skip to main content

Parameters vs arguments

A quick terminology note: parameters are the variables in the function definition. Arguments are the actual values you pass when calling the function.
In practice, people use the terms interchangeably. Don’t worry about it.
Python mental model: JavaScript is more permissive than Python here. If you pass too few arguments, the missing ones become undefined (instead of raising a TypeError). If you pass extra arguments, JavaScript ignores them unless you collect them with a rest parameter (...args).

Default parameters

Give parameters a fallback value when no argument is provided:
Same concept, same position — defaults go in the parameter list. JavaScript uses =, Python uses =. No surprises here.
One important JavaScript difference: default parameters are used when the argument is missing or explicitly undefined. Passing null does not use the default.

Practical example

Put required parameters first, optional parameters (with defaults) last. This is the same convention as Python.

Rest parameters

Collect any number of arguments into an array using ...:
The rest parameter ...numbers gathers all arguments into a real array. You can then use array methods on it.
JavaScript uses ...args, Python uses *args. Same idea.
In JavaScript, ... is used in multiple places (rest parameters, spread syntax). In Python, *args and **kwargs are split into separate syntaxes/uses. Same family of idea, different syntax rules.
The rest parameter must be the last parameter. function bad(...args, last) is a syntax error.

Destructuring parameters

When a function takes an object, you can destructure it right in the parameter list:
This is a pattern you’ll see everywhere in React. Component props are destructured this way:

Destructuring with defaults

Combine destructuring and default values:
Destructured parameters with defaults are the cleanest way to handle options objects. You’ll see this pattern in API client functions, React components, and configuration.
Python mental model: this is often nicer than passing a long list of positional args, and it plays a similar role to keyword-argument style APIs (func(url=..., timeout=...)) — but in JavaScript you’re usually passing a single options object.

What’s next?

You know how to define functions and pass data into them. Next, let’s understand where variables live — scope determines which parts of your code can see which variables.

Understanding scope

How JavaScript determines where variables are accessible