- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are JavaScript symbols?
The symbol data type is a primitive data type. They were introduced in ES6 and are completely unique and created using the Symbol() factory function which returns the Symbol.
Following is the code for JavaScript symbols −
Example
<!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; } .result { font-size: 18; color: blueviolet; font-weight: 500; } </style> </head> <body> <h1>JavaScript symbols</h1> <div class="result"></div> <button class="Btn">CLICK HERE</button> <h3>Click on the above button to display and compare symbols</h3> <script> let BtnEle = document.querySelector(".Btn"); let resEle = document.querySelector(".result"); let sym1 = Symbol("test"); let sym2 = Symbol("test"); BtnEle.addEventListener("click", () => { console.log(sym1); console.log(sym2); if (sym1 !== sym2) { resEle.innerHTML = "The symbols are not equal"; } }); </script> </body> </html>
Output
On clicking the ‘CLICK HERE’ button and inspecting the output in console −
- Related Articles
- What are Elements, Compounds and Symbols?
- What are the special symbols in C language?
- What are symbols in a JavaFX line chart. How to disable them?
- HTML Symbols
- Can variables have symbols in it like the percentage symbols %?
- What are JavaScript Identifiers?
- What are javascript sets?
- What are JavaScript basics?
- What are JavaScript Operators
- $g=frac{GM}{R^2}$, what does these symbols denote?
- What are events in JavaScript?
- What are JavaScript Bitwise Operators?
- What are JavaScript language resources?
- What are Comments in JavaScript?
- What are operators in JavaScript?

Advertisements