JavaScript symbol.description property

JavascriptWeb DevelopmentFront End TechnologyObject Oriented Programming

The symbol.description property in JavaScript converts a Symbol object to a primitive value. The syntax is as follows −

Symbol()[Symbol.toPrimitive](hint);

Example

 Live Demo

<!DOCTYPE html>
<html>
<body>
<h2>Demo Heading</h2>
<p>Click to display...</p>
<button onclick="display()">Result</button>
<p id="test"></p>
<script>
   function display() {
      const val = Symbol('john');
      console.log(val[Symbol.toPrimitive]);
   }
</script>
</body>
</html>

Output

Click the “Result” button −

Example

 Live Demo

<!DOCTYPE html>
<html>
<body>
<h2>Demo Heading</h2>
<p>Click to display...</p>
<button onclick="display()">Result</button>
<p id="test"></p>
<script>
   function display() {
      const val = Symbol(2465);
      var res = val[Symbol.toPrimitive](99);
      console.log(res)
   }
</script>
</body>
</html>

Output

Click the “Result” button and get the result in Console −

raja
Published on 17-Dec-2019 11:01:11
Advertisements