| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Functions/arguments | [Back] [Original] |
Get to know MDN better
function func1(a, b, c) {
console.log(arguments[0]);
// : 1
console.log(arguments[1]);
// : 2
console.log(arguments[2]);
// : 3
}
func1(1, 2, 3);
3
arguments[0]; // 1
arguments[1]; // 2
arguments[2]; // 3
arguments Math.min()
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[1] = "new value";
arguments
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
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 length 0 Array forEach() map() slice()Array.from() Array
const args = Array.prototype.slice.call(arguments);
// or
const args = Array.from(arguments);
// or
const args = [...arguments];
length Function.prototype.apply()
function midpoint() {
return (
(Math.min.apply(null, arguments) + Math.max.apply(null, arguments)) / 2
);
}
console.log(midpoint(3, 1, 4, 1, 5)); // 3
function myConcat(separator) {
const args = Array.prototype.slice.call(arguments, 1);
return args.join(separator);
}
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"
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;
}
list("u", "One", "Two", "Three");
// "<ul><li>One</li><li>Two</li><li>Three</li></ul>"
typeof arguments 'object'
console.log(typeof arguments); // 'object'
arguments
console.log(typeof arguments[0]); //
| ECMAScript 2027 LanguageSpecification # sec-arguments-exotic-objects |
| Web Proxy Viewer | New URL | Original Page |