--- id: javascript-function-arguments title: "JavaScript Function Arguments" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["JS function arguments", "function parameters", "arguments object", "default parameters", "rest parameter", "pass by value", "pass by reference"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.89 created_at: 2026-06-23 updated_at: 2026-06-23 review_reason: "" merge_history: [] tags: ["javascript", "js", "web", "frontend", "w3schools", "functions", "arguments", "parameters"] raw_sources: ["https://www.w3schools.com/js/js_function_arguments.asp"] applied_in: [] github_commit: "" --- # [[JavaScript Function Arguments]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) Parameters are the names listed in a function definition; arguments are the real values passed in β€” and JavaScript never checks their type or count, so missing arguments become `undefined`. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Parameters vs. arguments** β€” parameters are the *names* in the function definition; arguments are the *real values* passed to and received by the function. [S1] - **Order matters** β€” arguments are assigned to parameters in the order they appear. [S1] - **No type or count checking** β€” JavaScript function definitions do not specify data types, do not perform type checking, and do not check the number of arguments received. [S1] - **Missing arguments become `undefined`** β€” calling with fewer arguments than parameters leaves the missing ones `undefined`. [S1] - **`arguments` object** β€” every function has a built-in `arguments` object containing an array of the arguments used at call time, reachable even when more arguments are passed than declared. [S1] - **Pass by value vs. reference** β€” primitives are passed by value (changes are not reflected outside); objects behave like they are passed by reference (changing an object property changes the original). [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **Variadic via `arguments`** β€” loop over `arguments.length` to handle an indefinite number of inputs without declaring parameters. [S1] - **Default parameter guard** β€” set a default with `y = 10` in the signature (ES2015), or the older `if (y === undefined) y = 2;` pattern. [S1] - **Rest parameter collection** β€” `...args` gathers an indefinite number of arguments into a real array for iteration with `for...of`. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) **Parameters vs. Arguments** Function **parameters** are the names listed in the function definition. **Arguments** are the real values passed to, and received by, the function. [S1] ```javascript function multiply(a, b) { return a * b; } let result = multiply(4, 5); ``` Here `a` and `b` are parameters; `4` and `5` are arguments. The argument `4` is assigned to parameter `a` and `5` to parameter `b`. [S1] **The Arguments Object** JavaScript functions have a built-in `arguments` object that contains an array of the arguments used when the function was invoked. This lets a function find, for instance, the highest value in a list of numbers: [S1] ```javascript x = findMax(1, 123, 500, 115, 44, 88); function findMax() { let max = -Infinity; for (let i = 0; i < arguments.length; i++) { if (arguments[i] > max) { max = arguments[i]; } } return max; } ``` Or sum all input values: [S1] ```javascript x = sumAll(1, 123, 500, 115, 44, 88); function sumAll() { let sum = 0; for (let i = 0; i < arguments.length; i++) { sum += arguments[i]; } return sum; } ``` If a function is called with too many arguments (more than declared), those arguments can still be reached using the `arguments` object. [S1] **The Order of Arguments Matters** Arguments are assigned to parameters in the order they appear. [S1] ```javascript function subtract(a, b) { return a - b; } let x1 = subtract(10, 5); let x2 = subtract(5, 10); ``` The two calls return different results because the order is different. [S1] **Arguments Can Be Variables** Arguments do not have to be values; they can also be variables. [S1] ```javascript let x = 5; let y = 6; function multiply(a, b) { return a * b; } multiply(x, y); ``` **Argument Rules** JavaScript function definitions do not specify data types for arguments. JavaScript functions do not perform type checking on the passed arguments. JavaScript functions do not check the number of arguments received. [S1] **Incorrect Arguments** Incorrect arguments can return incorrect answers: [S1] ```javascript function toCelsius(fahrenheit) { return (5/9) * (fahrenheit-32); } let value = toCelsius("John"); ``` **Missing Arguments** If a function is called with fewer arguments than parameters, the missing values become `undefined`. [S1] ```javascript function multiply(a, b) { return a * b; } multiply(4); ``` Here `b` is `undefined`, so the result is `NaN`. A JavaScript function does not perform any checking on parameter values. [S1] **Default Parameters** If a function is called with missing arguments, the missing values are set to `undefined`. Sometimes it is better to assign a default value to the parameter: [S1] ```javascript function myFunction(x, y) { if (y === undefined) { y = 2; } } ``` **Default Parameter Values** ECMAScript 2015 allows function parameters to have default values. The default value is used if no argument is provided. If `y` is not passed or `undefined`, then `y = 10`: [S1] ```javascript function myFunction(x, y = 10) { return x + y; } myFunction(5); ``` **Function Rest Parameter** The rest parameter (`...`) allows a function to treat an indefinite number of arguments as an array: [S1] ```javascript function sum(...args) { let sum = 0; for (let arg of args) sum += arg; return sum; } let x = sum(4, 9, 16, 25, 29, 100, 66, 77); ``` **Arguments are Passed by Value** The parameters in a function call are the function's arguments. JavaScript arguments are passed by value: the function only gets to know the values, not the argument's locations. If a function changes an argument's value, it does not change the parameter's original value. Changes to arguments are not visible (reflected) outside the function. [S1] **Objects are Passed by Reference** In JavaScript, object references are values. Because of this, objects will behave like they are passed by reference: if a function changes an object property, it changes the original value. Changes to object properties are visible (reflected) outside the function. [S1] **Common Mistakes** Confusing parameters and arguments (parameters are names, arguments are values); forgetting the order (arguments are assigned by position); missing arguments (use default values to avoid `undefined`). [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) The page's own snippets are the canonical applied examples β€” `multiply`/`subtract` for parameter binding, `findMax`/`sumAll` for the `arguments` object, and `sum(...args)` for the rest parameter. No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Default parameter value (ES2015): ```javascript function myFunction(x, y = 10) { return x + y; } ``` Variadic via rest parameter: ```javascript function sum(...args) { let sum = 0; for (let arg of args) sum += arg; return sum; } ``` Variadic via the `arguments` object: ```javascript function sumAll() { let sum = 0; for (let i = 0; i < arguments.length; i++) { sum += arguments[i]; } return sum; } ``` ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) No contradictions found in the source. The page notes a version distinction: default parameter values are an ECMAScript 2015 feature, contrasted with the older `if (y === undefined)` guard pattern. [S1] ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual (μ‹€μ œ 적용 사둀 발견 μ‹œ applied/validated둜 승격 κ°€λŠ₯) - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.89 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[JavaScript Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[JavaScript Function Expressions]], [[JavaScript Arrow Functions]], [[JavaScript Objects]] - **μ°Έμ‘° λ§₯락:** Referenced whenever defining functions and reasoning about how values reach them, including variadic functions and defaults. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” JavaScript Function Arguments β€” https://www.w3schools.com/js/js_function_arguments.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Function Arguments" page (Astra wiki-curation, P-Reinforce v3.1 format).