This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (true) { | |
| console.log('a => ', a); // undefined | |
| console.log('b => ', b); // b is not defined | |
| var a = 'hacker'; | |
| let b = 'pinky'; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var a = 'hacker'; // a = 'hacker' | |
| var a = 'moon'; // a = 'moon' | |
| let b = 'hacker'; // b = 'hacker' | |
| let b = 'pinky'; // Identifier 'b' has already been declared |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const a = 'haha'; // a = 'haha' | |
| a = 'hihi'; // Assignment to constant variable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const a = { prop: 'haha' }; | |
| console.log('prop => ', a.prop); // haha | |
| a.prop = 'hihi'; | |
| console.log('prop => ', a.prop); // hihi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var s = new Set(); | |
| s.add(1).add(2).add(1); | |
| console.log('Size of s => ', s.size); // 2 | |
| console.log('s has 2 => ', s.has(2)); // true | |
| s.delete(2); | |
| console.log('s has 2 => ', s.has(2)); // false | |
| s.clear(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let ws = new WeakSet(); | |
| let value = {a: 'hacker'}; | |
| ws.add(value).add({b: 'moon'}); | |
| console.log(ws); // WeakSet {Object {a: "hacker"}, Object {b: "moon"}} | |
| // after the garbage collector has run | |
| console.log(ws); // WeakSet {Object {a: "hacker"}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let map = new Map(); | |
| let obj = {a: 'haha'}; | |
| map.set(obj, 'hihi').set(1, 1).set(1, 2); | |
| console.log('map has 1 => ', map.has(1)); // true | |
| console.log('value of 1 => ', map.get(1)); // 2 | |
| map.delete(1); | |
| console.log('map has 1 => ', map.has(1)); // false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let wm = new WeakMap(); | |
| let key = {a: 1}; | |
| wm.set(key, 1).set({b: 2}, 2); | |
| console.log(wm); // WeakMap {Object {a: 1} => 1, Object {b: 2} => 2} | |
| // after the garbage collector has run | |
| console.log(wm); // WeakMap {Object {a: 1} => 1} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let a = (a) => { | |
| return a + 1; | |
| }; | |
| let b = b => b + 1; | |
| let c = () => ({hacker: 'moon'}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let obj1 = { | |
| cb: function () { | |
| let that = this; | |
| let fun = function () { | |
| console.log('this => ', this); // undefined | |
| console.log('that => ', that); // { cb: [Function] } | |
| }; | |
| fun(); | |
| } |