SlideShare a Scribd company logo
JAVASCRIPT
SYMBOL
Symbol
It is a primitive data type along with string,
number, boolean, null and undefined.
To create a new primitive symbol, you define
it with the following syntax.
let mySymbol = Symbol();
You can pass a parameter to Symbol(), and that
is used as the symbol description, useful just
for debugging purposes.
let mySecondSymbol = Symbol('orange');
Symbol
They are unique, and every time you invoke
Symbol(), you get a new and unique symbol
which is guaranteed to be different from all
other symbols.
You can see it here,
Symbol() === Symbol() //false
Symbol('orange') === Symbol('orange') // false
console.log(Symbol()); //Symbol()
console.log(Symbol('orange')); //Symbol(orange)
Even though every symbol gives a unique value we
can’t view them by logging.
Symbol
It won’t be enumerated in for…in loops, and are
ignored by functions such as JSON.stringify(),
Object.keys() and Object.getOwnPropertyNames().
This makes them ideal for properties that you
don’t want to be included when serializing an
object.
const user = {};
const email = Symbol();
user.name = 'Elon';
user.age = 48;
user[email] = 'elon@tesla.com';
Object.keys(user);
// [ "name", "age" ]
JSON.stringify(user);
// "{"name":"Elon","age":48}"
Let’s say you created a user object
as shown in the previous slide and
have an object like,
What are the ways you can retrieve
the value “elon@tesla.com” from the
user object?
Comment your answers below 👇
{name: "Elon", age: 48, Symbol(): "elon@tesla.com"}
💡Question for you:

More Related Content

PDF
Денис Лебедев, Swift
PDF
Quick swift tour
PDF
Type level programming in Scala
PDF
Version comaparison in JavaScript
PDF
Currying in JavaScript
PDF
JS Testing Frameworks
PDF
Cool usage of Encoding and Decoding a URI in Javascript
PDF
Iterables and Iterators in JavaScript
Денис Лебедев, Swift
Quick swift tour
Type level programming in Scala
Version comaparison in JavaScript
Currying in JavaScript
JS Testing Frameworks
Cool usage of Encoding and Decoding a URI in Javascript
Iterables and Iterators in JavaScript

More from Ideas2IT Technologies (20)

PDF
String comparison in javascript
PDF
Json.parse() in JavaScript
PDF
Bubble sort in Java Script
PDF
Performance analysis in merging arrays - JavaScript
PDF
Nullish coalescing in JavaScript
PDF
Conditionally add keys in JavaScript
PDF
What is Big O in JavaScript - Part-1
PDF
Variable hoisting in JavaScript
PDF
Formidable ES6 spread operator in JavaScript
PDF
Logging in JavaScript - Part-5
PDF
Logging in JavaScript - Part-4
PDF
Logging in JavaScript - Part-3
PDF
Logging in JavaScript - part-2
PDF
Logging in JavaScript - part-1
PDF
Array vs set in JavaScript
PDF
Arguments Object in JavaScript
PDF
Pollyfills in JavaScript
PDF
Async await in JavaScript - part-3
PDF
Async await in JavaScript
PDF
Regex Cheat Sheet in JavaScript - part-2
String comparison in javascript
Json.parse() in JavaScript
Bubble sort in Java Script
Performance analysis in merging arrays - JavaScript
Nullish coalescing in JavaScript
Conditionally add keys in JavaScript
What is Big O in JavaScript - Part-1
Variable hoisting in JavaScript
Formidable ES6 spread operator in JavaScript
Logging in JavaScript - Part-5
Logging in JavaScript - Part-4
Logging in JavaScript - Part-3
Logging in JavaScript - part-2
Logging in JavaScript - part-1
Array vs set in JavaScript
Arguments Object in JavaScript
Pollyfills in JavaScript
Async await in JavaScript - part-3
Async await in JavaScript
Regex Cheat Sheet in JavaScript - part-2
Ad

Recently uploaded (20)

PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Transform Your Business with a Software ERP System
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
Introduction to Artificial Intelligence
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
AI in Product Development-omnex systems
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
ai tools demonstartion for schools and inter college
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Essential Infomation Tech presentation.pptx
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Nekopoi APK 2025 free lastest update
PDF
top salesforce developer skills in 2025.pdf
Operating system designcfffgfgggggggvggggggggg
Transform Your Business with a Software ERP System
wealthsignaloriginal-com-DS-text-... (1).pdf
Introduction to Artificial Intelligence
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Reimagine Home Health with the Power of Agentic AI​
AI in Product Development-omnex systems
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PTS Company Brochure 2025 (1).pdf.......
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
How to Migrate SBCGlobal Email to Yahoo Easily
ai tools demonstartion for schools and inter college
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Essential Infomation Tech presentation.pptx
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Nekopoi APK 2025 free lastest update
top salesforce developer skills in 2025.pdf
Ad

JavaScript symbols

  • 2. Symbol It is a primitive data type along with string, number, boolean, null and undefined. To create a new primitive symbol, you define it with the following syntax. let mySymbol = Symbol(); You can pass a parameter to Symbol(), and that is used as the symbol description, useful just for debugging purposes. let mySecondSymbol = Symbol('orange');
  • 3. Symbol They are unique, and every time you invoke Symbol(), you get a new and unique symbol which is guaranteed to be different from all other symbols. You can see it here, Symbol() === Symbol() //false Symbol('orange') === Symbol('orange') // false console.log(Symbol()); //Symbol() console.log(Symbol('orange')); //Symbol(orange) Even though every symbol gives a unique value we can’t view them by logging.
  • 4. Symbol It won’t be enumerated in for…in loops, and are ignored by functions such as JSON.stringify(), Object.keys() and Object.getOwnPropertyNames(). This makes them ideal for properties that you don’t want to be included when serializing an object. const user = {}; const email = Symbol(); user.name = 'Elon'; user.age = 48; user[email] = 'elon@tesla.com'; Object.keys(user); // [ "name", "age" ] JSON.stringify(user); // "{"name":"Elon","age":48}"
  • 5. Let’s say you created a user object as shown in the previous slide and have an object like, What are the ways you can retrieve the value “elon@tesla.com” from the user object? Comment your answers below 👇 {name: "Elon", age: 48, Symbol(): "elon@tesla.com"} 💡Question for you: