Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

Regular parameters in JavaScript are identifiers declared within a function’s signature that act as local variables bound to the arguments passed during function invocation. They establish the function’s expected arity and provide a mechanism for data ingestion into the function’s execution context.
function executeOperation(param1, param2) {
    // param1 and param2 are regular parameters
}

const arg1 = 10;
const arg2 = 20;
executeOperation(arg1, arg2); // arg1 and arg2 are arguments bound to the parameters

Parameter Binding and Arity

JavaScript does not enforce strict arity matching between the declared parameters and the provided arguments during invocation.
  • Under-application: If fewer arguments are passed than declared parameters, the unmapped parameters are automatically initialized to the primitive value undefined.
  • Over-application: If more arguments are passed than declared parameters, the excess arguments are not bound to any named identifier. They are ignored by the parameter list but remain accessible internally via the local arguments object.

The arguments Object Aliasing

In non-arrow functions, regular parameters exhibit specific aliasing behaviors with the local arguments object. This behavior diverges based on the execution mode and the complexity of the parameter list:
  • Non-Strict Mode with Simple Parameters: If the function uses a simple parameter list (no default parameters, rest parameters, or destructuring), regular parameters are dynamically mapped to the arguments object. Modifying a named parameter automatically updates the corresponding index in the arguments object, and conversely, mutating the arguments object updates the named parameter. Crucially, this bidirectional mapping only applies to arguments that were actually passed during invocation. If a parameter is under-applied (receives undefined because no argument was provided), modifying the parameter does not map it to or update the arguments object.
  • Strict Mode or Non-Simple Parameters: The dynamic mapping is completely disabled. If the function is in strict mode, or if the signature contains any non-simple parameters (ES6+), regular parameters and the arguments object remain entirely separate. Modifying a parameter identifier has no effect on the arguments object.
function nonStrictAlias(param1, param2) {
    param1 = "mutated";
    param2 = "mutated";
    console.log(arguments[0]); // Outputs: "mutated" (mapped because argument was passed)
    console.log(arguments[1]); // Outputs: undefined (unmapped because argument was omitted)
}
nonStrictAlias("initial"); // Invocation with only one argument

function strictAlias(param) {
    "use strict";
    param = "mutated";
    console.log(arguments[0]); // Outputs: "initial" (mapping severed by strict mode)
}
strictAlias("initial");

function nonSimpleAlias(param = "default") {
    param = "mutated";
    console.log(arguments[0]); // Outputs: "initial" (mapping severed by non-simple parameter)
}
nonSimpleAlias("initial");

Evaluation Strategy

JavaScript binds arguments to regular parameters using a strict “pass-by-value” evaluation strategy.
  • Primitive Values: The parameter receives an independent copy of the primitive value. Reassigning or modifying the parameter inside the function does not affect the original argument.
  • Object Values: The parameter receives a copy of the reference pointing to the object in memory (a concept often referred to as “call-by-sharing”). Reassigning the parameter identifier to a completely new object does not affect the external reference, but mutating the properties of the referenced object will mutate the original object.

Scope and Shadowing

Regular parameters are scoped to the function’s local execution context. If a parameter shares an identifier name with a variable in an outer lexical environment, the parameter shadows the outer variable for the duration of the function’s execution.

Strict Mode Constraints

In non-strict mode, JavaScript permits duplicate parameter names within a function signature. In such cases, the last duplicated parameter shadows the preceding ones, receiving the value of the corresponding argument. However, when strict mode is enabled, declaring duplicate regular parameters results in a fatal syntax error.
// Non-strict mode: Allowed (param evaluates to the second argument)
function nonStrictFunc(param, param) {} 

// Strict mode: Throws SyntaxError: Duplicate parameter name not allowed in this context
function strictFunc(param, param) {
    "use strict";
}
Master JavaScript with Deep Grasping Methodology!Learn More