Contenido del Curso
Introduction to JavaScript (staging)
Introduction to JavaScript (staging)
Symbols 1/3
The symbol is a primitive data type that is used to create a unique identifier. Symbols are unchallengeable and unique.
Creation of symbols
We use the global Symbol()
function to create a new symbol. We will work briefly with the functions in the later section but you have to learn that to create a primitive symbol we will use Symbol()
.
let s = Symbol('foo'); console.log(s.toString());
Note: Symbol variable should be converted to string if you want to use it as a string value. That can be done by using .toString()
method.
A unique value is created every time the Symbol()
function is called or used and these values are not equal to each other (they are unique).
console.log(Symbol() === Symbol());
Even when we pass equal arguments, the result is still different, for example:
console.log(Symbol('Berlin') == Symbol('Berlin'));
Tarea
You have to check that Symbol('Monaco')
and Symbol('Istanbul')
are equal or not and display the result on the console.
Tarea
You have to check that Symbol('Monaco')
and Symbol('Istanbul')
are equal or not and display the result on the console.
¿Todo estuvo claro?
Symbols 1/3
The symbol is a primitive data type that is used to create a unique identifier. Symbols are unchallengeable and unique.
Creation of symbols
We use the global Symbol()
function to create a new symbol. We will work briefly with the functions in the later section but you have to learn that to create a primitive symbol we will use Symbol()
.
let s = Symbol('foo'); console.log(s.toString());
Note: Symbol variable should be converted to string if you want to use it as a string value. That can be done by using .toString()
method.
A unique value is created every time the Symbol()
function is called or used and these values are not equal to each other (they are unique).
console.log(Symbol() === Symbol());
Even when we pass equal arguments, the result is still different, for example:
console.log(Symbol('Berlin') == Symbol('Berlin'));
Tarea
You have to check that Symbol('Monaco')
and Symbol('Istanbul')
are equal or not and display the result on the console.
Tarea
You have to check that Symbol('Monaco')
and Symbol('Istanbul')
are equal or not and display the result on the console.
¿Todo estuvo claro?
Symbols 1/3
The symbol is a primitive data type that is used to create a unique identifier. Symbols are unchallengeable and unique.
Creation of symbols
We use the global Symbol()
function to create a new symbol. We will work briefly with the functions in the later section but you have to learn that to create a primitive symbol we will use Symbol()
.
let s = Symbol('foo'); console.log(s.toString());
Note: Symbol variable should be converted to string if you want to use it as a string value. That can be done by using .toString()
method.
A unique value is created every time the Symbol()
function is called or used and these values are not equal to each other (they are unique).
console.log(Symbol() === Symbol());
Even when we pass equal arguments, the result is still different, for example:
console.log(Symbol('Berlin') == Symbol('Berlin'));
Tarea
You have to check that Symbol('Monaco')
and Symbol('Istanbul')
are equal or not and display the result on the console.
Tarea
You have to check that Symbol('Monaco')
and Symbol('Istanbul')
are equal or not and display the result on the console.
¿Todo estuvo claro?
The symbol is a primitive data type that is used to create a unique identifier. Symbols are unchallengeable and unique.
Creation of symbols
We use the global Symbol()
function to create a new symbol. We will work briefly with the functions in the later section but you have to learn that to create a primitive symbol we will use Symbol()
.
let s = Symbol('foo'); console.log(s.toString());
Note: Symbol variable should be converted to string if you want to use it as a string value. That can be done by using .toString()
method.
A unique value is created every time the Symbol()
function is called or used and these values are not equal to each other (they are unique).
console.log(Symbol() === Symbol());
Even when we pass equal arguments, the result is still different, for example:
console.log(Symbol('Berlin') == Symbol('Berlin'));
Tarea
You have to check that Symbol('Monaco')
and Symbol('Istanbul')
are equal or not and display the result on the console.