Computer >> Máy Tính >  >> Lập trình >> Javascript

thuộc tính Symbol.description trong JavaScript

Thuộc tính Symbol.description trả về mô tả tùy chọn của các đối tượng biểu tượng và là thuộc tính chỉ đọc.

Sau đây là mã cho thuộc tính Symbol.description -

Ví dụ

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
   body {
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
   }
   div {
      font-size: 20px;
      font-weight: 500;
   }
</style>
</head>
<body>
<h1>JavaScript symbol.description property</h1>
<div class="sample"></div>
<button class="Btn">CLICK HERE</button>
<h3>
Click on the above button to get the description for the symbols.
</h3>
<script>
   let fillEle = document.querySelector(".sample");
   let desc = [];
   desc.push(Symbol("New").description);
   desc.push(Symbol("Hello").description);
   desc.push(Symbol.iterator.description);
   document.querySelector(".Btn").addEventListener("click", () => {
      desc.forEach((item) => (fillEle.innerHTML += item + "<br>"));
   });
</script>
</body>
</html>

Đầu ra

thuộc tính Symbol.description trong JavaScript

Khi nhấp vào nút “BẤM VÀO ĐÂY” -

thuộc tính Symbol.description trong JavaScript