Function.prototype.length

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

함수 인스턴스의 length 데이터 속성은 함수가 기대하는 인자의 수를 나타냅니다.

시도해보기

function func1() {}

function func2(a, b) {}

console.log(func1.length);
// Expected output: 0

console.log(func2.length);
// Expected output: 2

숫자

Property attributes of Function.prototype.length
쓰기 가능불가능
열거 가능불가능
설정 가능가능

설명

length는 함수 객체의 속성으로, 함수가 얼마나 많은 인수를 기대하는지 나타냅니다, 즉 형식 매개변수의 수. 이 수는 나머지 매개변수를 포함하지 않습니다. 그에 반해, arguments.length는 함수에 지역(local)이고 실제로 함수에 전달된 인수의 수를 제공합니다.

Function 객체의 length 속성은 함수가 얼마나 많은 인수를 기대하는지 나타냅니다. 이는 형식 매개변수의 수 입니다. 이 숫자는 나머지 매개변수를 포함하지 않으며 기본 값을 가진 첫 번째 매개변수 이전의 매개 변수만 포함합니다. 반면 arguments.length는 하나의 함수에 국한되어 실제로 함수에 전달된 인수의 수를 제공합니다.

Function 생성자는 그 자체로 function 객체입니다. 그 length 데이터 속성은 값이 1입니다.

역사적인 이유로 인해 Function.prototype은 호출 가능한 자체입니다. Function.prototypelength속성 값은 0입니다.

예제

함수 length 사용하기

js
console.log(Function.length); // 1

console.log((() => {}).length); // 0
console.log(((a) => {}).length); // 1
console.log(((a, b) => {}).length); // 2 etc.

console.log(((...args) => {}).length);
// 0, 나머지 매개변수는 세지 않습니다

console.log(((a, b = 1, c) => {}).length);
// 1, 기본값을 가진 매개변수 이전의 매개변수만 셉니다

명세서

Specification
ECMAScript® 2025 Language Specification
# sec-function-instances-length

브라우저 호환성

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
length
Configurable: true

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

참조