console.count()
메서드는 특정 count()
호출의 횟수를 세어 출력합니다.
주의: 이 기능은 Web Worker에서 사용할 수 있습니다.
구문
console.count([label]);
매개변수
label
OptionalString
. 지정한 경우, 이 레이블을 지정한 count() 호출의 수를 출력합니다. 누락한 경우"default"
를 지정한 것처럼 동작합니다.
예제
let user = "";
function greet() {
console.count();
return "hi " + user;
}
user = "bob";
greet();
user = "alice";
greet();
greet();
console.count();
위 코드의 출력 결과는 다음과 같은 형태입니다.
"default: 1" "default: 2" "default: 3" "default: 4"
레이블을 명시하지 않았기 때문에 default
로 나타납니다.
첫 번째 count()
의 매개변수에는 user
변수를 제공하고, 두 번째에는 문자열 "alice"
를 제공할 경우...
let user = "";
function greet() {
console.count(user);
return "hi " + user;
}
user = "bob";
greet();
user = "alice";
greet();
greet();
console.count("alice");
다음과 같이 출력합니다.
"bob: 1" "alice: 1" "alice: 2" "alice: 3"
명세
Specification | Status | Comment |
---|---|---|
Console API The definition of 'console.count()' in that specification. |
Living Standard | Initial definition |
브라우저 호환성
BCD tables only load in the browser
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.