// Generator function using function* syntax
function* numberGenerator() {
yield 1;
yield 2;
yield 3;
}
const gen = numberGenerator();
console.log(gen.next().value); // 1
console.log(gen.next().value); // 2
console.log(gen.next().value); // 3
// Creating unique Symbols
const id1 = Symbol("id");
const id2 = Symbol("id");
console.log(id1 === id2); // false (Symbols are always unique)
// Using Symbol as an object key
const user = {
name: "Amit",
[id1]: 101
};
console.log(user.name); // Amit
console.log(user[id1]); // 101
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter