[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Functions/arguments [Back]  [Original]

arguments - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

arguments

Baseline *

20157

*

arguments (array-like)

function func1(a, b, c) {
  console.log(arguments[0]);
  // : 1

  console.log(arguments[1]);
  // : 2

  console.log(arguments[2]);
  // : 3
}

func1(1, 2, 3);

:

arguments arguments 0

3

js
arguments[0]; // 1 
arguments[1]; // 2 
arguments[2]; // 3 

arguments Math.min()

js
function longestString() {
  let longest = "";
  if (arguments.length === 0) {
    throw new TypeError("1 ");
  }
  for (const arg of arguments) {
    if (arg.length > longest.length) {
      longest = arg;
    }
  }
  return longest;
}

arguments.length length

js
arguments[1] = "new value";

arguments

js
function func(a) {
  arguments[0] = 99; // arguments[0]  a 
  console.log(a);
}
func(10); // 99

function func2(a) {
  a = 99; // a  arguments[0] 
  console.log(arguments[0]);
}
func2(10); // 99

arguments arguments

js
function funcWithDefault(a = 55) {
  arguments[0] = 99; // arguments[0]  a 
  console.log(a);
}
funcWithDefault(10); // 10

function funcWithDefault2(a = 55) {
  a = 99; // a  arguments[0] 
  console.log(arguments[0]);
}
funcWithDefault2(10); // 10

// 
function funcWithDefault3(a = 55) {
  console.log(arguments[0]);
  console.log(arguments.length);
}
funcWithDefault3(); // undefined; 0

arguments arguments

: "use strict";

arguments

arguments arguments length 0 Array forEach() map() slice()Array.from() Array

js
const args = Array.prototype.slice.call(arguments);
// or
const args = Array.from(arguments);
// or
const args = [...arguments];

length Function.prototype.apply()

js
function midpoint() {
  return (
    (Math.min.apply(null, arguments) + Math.max.apply(null, arguments)) / 2
  );
}

console.log(midpoint(3, 1, 4, 1, 5)); // 3

arguments.callee

arguments.length

arguments[Symbol.iterator]()

arguments

js
function myConcat(separator) {
  const args = Array.prototype.slice.call(arguments, 1);
  return args.join(separator);
}

js
myConcat(", ", "red", "orange", "blue");
// "red, orange, blue"

myConcat("; ", "elephant", "giraffe", "lion", "cheetah");
// "elephant; giraffe; lion; cheetah"

myConcat(". ", "sage", "basil", "oregano", "pepper", "parsley");
// "sage. basil. oregano. pepper. parsley"

HTML

HTML "u" "o"

js
function list(type) {
  let html = `<${type}l><li>`;
  const args = Array.prototype.slice.call(arguments, 1);
  html += args.join("</li><li>");
  html += `</li></${type}l>`; // 
  return html;
}

js
list("u", "One", "Two", "Three");
// "<ul><li>One</li><li>Two</li><li>Three</li></ul>"

typeof arguments

typeof arguments 'object'

js
console.log(typeof arguments); // 'object'

arguments

js
console.log(typeof arguments[0]); // 

ECMAScript 2027 LanguageSpecification
# sec-arguments-exotic-objects


Web Proxy Viewer  |  New URL  |  Original Page