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
| //For the following: | |
| var a = `foo ${b}`, b = `bar ${a}`; | |
| console.log(a); | |
| //Why would console.log output 'foo' and then 'undefined'? | |
| //Is it because b is defined after a? | |
| //If that's true, then why does the following code output 'foo bar undefined'?: | |
| var b = `bar ${a}`, a = `foo ${b}`; | |
| console.log(a); |
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 myObject = function(obj){ | |
| obj.sayName = function(){ | |
| console.log(this.name); | |
| } | |
| } | |
| let me = { | |
| name: 'Jasmine' | |
| } |
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 createUser = function(name){ | |
| return{ | |
| name, | |
| sayNames: function() {console.log(this.name)}, | |
| dog: { | |
| name: 'Jello', | |
| sayNames: function() {console.log(name + "'s dog's name is " + this.name)} | |
| } | |
| } | |
| } |
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
| //call | |
| let john = { | |
| name: 'John' | |
| } | |
| let hobbies = ['painting', 'cooking', 'biking']; | |
| let setName = function(hobby0, hobby1){ | |
| console.log(this.name + "'s hobbies are " + hobby0 + " and " + hobby1); | |
| } |
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 john = { | |
| name: 'John' | |
| } | |
| let hobbies = ['painting', 'cooking', 'biking']; | |
| let setName = function(hobby0, hobby1){ | |
| console.log(this.name + "'s hobbies are " + hobby0 + " and " + hobby1); | |
| } |
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 john = { | |
| name: 'John' | |
| } | |
| let hobbies = ['painting', 'cooking', 'biking']; | |
| let setName = function(hobby0, hobby1){ | |
| console.log(this.name + "'s hobbies are " + hobby0 + " and " + hobby1); | |
| } |
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 Dog = function(breed){ | |
| this.breed = breed; | |
| } | |
| let chihuahua = new Dog('Chihuahua'); | |
| console.log(chihuahua); // will output Dog { breed: 'Chihuahua' } |
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 global = 'I see global.' | |
| function scopeFunction(){ | |
| console.log(global); | |
| } | |
| scopeFunction(); // outputs 'I see global.' |
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 myFunction(){ | |
| var localFunction = 'I see local'; | |
| console.log(localFunction); | |
| } | |
| myFunction(); // outputs 'I see functional scope' | |
| console.log(localFunction); // Outputs an error 'localFunction is not defined' |
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 = 'hi'; | |
| function myFunction(){ | |
| console.log(a); | |
| var a = 'hello'; | |
| console.log(a); | |
| } | |
| myFunction(); |
OlderNewer