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
| // Wolf | |
| // - Properties | |
| // -- fur color | |
| // -- eye color | |
| // -- size | |
| // -- gender | |
| // -- age | |
| // - Actions | |
| // -- walk/run |
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 myOtherVar = 10 | |
| function a() { | |
| console.log('myVar', myVar) | |
| b() | |
| } | |
| function b() { | |
| console.log('myOtherVar', myOtherVar) | |
| c() |
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 myOtherVar = undefined | |
| var myVar = undefined | |
| function a() {...} | |
| function b() {...} | |
| function c() {...} |
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
| "myVar" undefined | |
| "myOtherVar" 10 | |
| "Hello world!" |
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
| function a() { | |
| console.log('myVar', myVar) | |
| b() | |
| } |
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
| // scope & scope chain | |
| function a() { | |
| var myOtherVar = 'inside A' | |
| b() | |
| } | |
| function b() { | |
| var myVar = 'inside B' |
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
| // scope & scope chain commented | |
| // was declared globally, outer reference is global | |
| function a() { | |
| // variable created inside context of a | |
| var myOtherVar = 'inside A' | |
| // b called inside a, but was lexically declared in the global context | |
| b() | |
| } |
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
| function loopScope () { | |
| var i = 50 | |
| var j = 99 | |
| for (var i = 0; i < 10; i++) {} | |
| console.log('i =', i) | |
| for (let j = 0; j < 10; j++) {} |
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
| // block scoping - literal blocks | |
| function blockScope () { | |
| let a = 5 | |
| { | |
| const blockedVar = 'blocked' | |
| var b = 11 | |
| a = 9000 | |
| } |
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
| // Closure Example | |
| function exponent (x) { | |
| // returns a new function to be called later | |
| // this function remembers the x argument | |
| return function (y) { | |
| // ** is the exponentiation operator | |
| // same thing as Math.pow() or y to the power of x | |
| return y ** x | |
| } |