With symbols you can manipulate how 'built-in' types work
Code Example
//Symbols in ES6 - Well Known Symbols
class Person {
}
//Access the person prototype and change the object prototype
Person.prototype[Symbol.toStringTag] = 'Person';
let person = new Person();
console.log(person);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
Example : Using the well known symbols to manipulate the built in array object
//Symbols in ES6 - Well Known Symbols Example with arrays
// Before Symbols
let numbers = [1, 2, 3];
console.log(numbers + 1);
//After Symbols using the toPrimitive function
numbers[Symbol.toPrimitive] = function() {
return 999;
}
console.log(numbers + 1);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15