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 is hoisted during the creation of the context execution | |
| //It exists in memory with undefined as a value | |
| myVar = "I am a var"; //Perfectly ok | |
| console.log(myVar); //Prints "I am a var" | |
| var myVar; | |
| //OR | |
| console.log(myVar); //Perfectly ok, prints "undefined" | |
| var myVar; |
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
| //myLet is hoisted during the creation of the context execution | |
| //It exists in memory with undefined as a value | |
| //But we are not allowed to access it before declaring it | |
| myLet = "I am a let"; //Throws: Cannot access 'myLet' before initialization | |
| console.log(myLet); | |
| let myLet; |
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
| //myConst is hoisted during the creation of the context execution | |
| //It exists in memory with undefined as a value | |
| //But we are not allowed to access it before declaring it | |
| myConst = "I am a const"; //Throws: Cannot access 'myConst' before initialization | |
| console.log(myConst); //line not reached due to error thrown above | |
| const myConst = "Initializer"; |
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
| //sayHi is hoisted during the creation of the context execution | |
| sayHi("Bulma"); //calls the function and prints "Bulma says hi" | |
| function sayHi(who) { | |
| console.log(who + " says hi"); | |
| } |
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
| attack("Son Goku"); | |
| var attack = function(who) { | |
| console.log(who + " attacked you!"); | |
| }; |
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
| attack("Son Goku"); | |
| function attack(who) { | |
| console.log(who + " attacked you!"); | |
| } |
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 saiyan = { | |
| firstName: "Son Goku", | |
| attackName: "Kamehameha", | |
| address: { | |
| street: "439 East District", | |
| city: "Paozu" | |
| } | |
| }; |
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 attack() { | |
| console.log("You have been attacked!"); | |
| } | |
| attack.newProperty = "holololo"; | |
| console.log(attack.newProperty); //holololo |
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 multiplyByTen = function(num) { | |
| return num * 10; | |
| }; | |
| function mapArray(arr, fn) { | |
| var resultingArr = []; | |
| for (var i = 0; i < arr.length; i++) { | |
| resultingArr.push(fn(arr[i])); | |
| } | |
| return resultingArr; |
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 attack(attacker) { | |
| return function(attackName) { | |
| console.log(attacker + " throws a " + attackName); | |
| }; | |
| } | |
| var throwAttack = attack("Son Goku"); | |
| throwAttack("Kamehameha"); |
OlderNewer