Symbol is identifiers that are used to refer to something else . it created to use as indentifier -
Rasi
Jan 13 '17 05:48
Symbol("$") !== Symbol("$")
var myKey = Symbol();
var Key1 = Symbol();
var Key2 = Symbol();
var obj ={};
obj[Key1]="Shyam";
obj[Key2]="Ram";
console.log(obj[Key1]); // Ram
console.log(obj[Key2]); // Shyam
console.log(Key2==Key1); // false
var player={};
player["isRunning"]=true;
var player={};
player[Symbol("isRunning")]=true;
var Product = (function() {
var name;
function Product(name) {
this.name = name;
}
Product.prototype.getName = function() {
return this.name;
};
return Product;
}());
var product = Product ('Apple');
console.log(product.getName());//Apple
delete product.name;//true
console.log(product.getName());//undefined
var Product= (function() {
var nameSymbol = Symbol('name');
function Product(name) {
this[nameSymbol] = name;
}
Product.prototype.getName = function() {
return this[nameSymbol];
};
return Product;
}());
var product = Product ('Apple');
console.log(product.getName());//Apple
delete product.name;//true
console.log(product.getName());//Apple