Symbol.prototype.description

Baseline Widely available

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

Symbol 값의 description 접근자 속성은 이 심볼에 대한 설명이 포함된 문자열을 반환하거나 설명이 없는 경우 undefined를 반환합니다.

시도해보기

console.log(Symbol("desc").description);
// Expected output: "desc"

console.log(Symbol.iterator.description);
// Expected output: "Symbol.iterator"

console.log(Symbol.for("foo").description);
// Expected output: "foo"

console.log(`${Symbol("foo").description}bar`);
// Expected output: "foobar"

설명

Symbol 객체는 디버깅에 사용할 수 있지만 심볼 자체에 접근하는 데는 사용할 수 없는 선택적인 설명과 함께 생성할 수 있습니다. Symbol.prototype.description 속성은 해당 설명을 읽는 데 사용할 수 있습니다. 이 속성은 둘러싸는 "Symbol()" 문자열을 포함하지 않으므로 Symbol.prototype.toString()과 다릅니다. 예제를 참조하세요.

예제

description 사용하기

js
Symbol("desc").toString(); // "Symbol(desc)"
Symbol("desc").description; // "desc"
Symbol("").description; // ""
Symbol().description; // undefined

// 잘 알려진 심볼
Symbol.iterator.toString(); // "Symbol(Symbol.iterator)"
Symbol.iterator.description; // "Symbol.iterator"

// 전역 심볼
Symbol.for("foo").toString(); // "Symbol(foo)"
Symbol.for("foo").description; // "foo"

명세서

Specification
ECMAScript® 2025 Language Specification
# sec-symbol.prototype.description

브라우저 호환성

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
description

Legend

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

Full support
Full support
Partial support
Partial support
Has more compatibility info.

같이 보기