Symbols 3/3
Accessing the Description of the Symbol()
We can access the description of the symbol by calling the .description
method.
9
1
2
let firstName = Symbol('Michael');
console.log(firstName.description);
12let firstName = Symbol('Michael'); console.log(firstName.description);
Tâche
Swipe to start coding
Create two symbols personName
and personAdress
by using Symbol()
give them the description of Name
and Address
and display their descriptions.
Solution
9
1
2
3
4
5
let personName = Symbol('Name');
let personAdress = Symbol('Address');
console.log(personName.description);
console.log(personAdress.description);
Summary
Symbol is a primitive data type that is used to create a unique identifier.
We use the global
Symbol()
function to create symbols.We can provide a
description
to aSymbol()
function as an optional argument.The description of the symbol can be accessed through the
.description
property.
Tout était clair ?
Merci pour vos commentaires !
Section 3. Chapitre 29
9
1
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion