This file contains 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
movieStar(); // Prints “TypeError : movieStar is not a function” | |
var movieStar = function () { // This is a function expression and therefore not hoisted | |
var name = “Philip Seymour Hoffman”; | |
console.log(name); | |
} |
This file contains 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 movieStar = function () { | |
var name = “Philip Seymour Hoffman”; | |
console.log(name); | |
} | |
movieStar(); // Prints “Philipp Seymour Hoffman” |
This file contains 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 businessStar; | |
function businessStar(){ | |
console.log(“Gary Vaynerchuck”); | |
} | |
console.log(businessStar); // Prints “function businessStar(){ console.log(“Gary Vaynerchuck”);}” |
This file contains 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 businessStar = “Gary Vaynerchuck”; | |
function businessStar(){ | |
console.log(“Gary Vaynerchuck”); | |
} | |
console.log(businessStar); // Prints “Gary Vaynerchuck” |
This file contains 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 greeting = "Hi, I am a global variable"; // global scope variable | |
function sayHello() { | |
var greeting = "Hi, I am a local variable"; // local scope variable | |
console.log(greeting); | |
} | |
sayHello(); // Prints "Hi, I am a local variable" | |
console.log(greeting); // Prints "Hi, I am a global variable" |
This file contains 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 greeting = "Hi there!"; // global scope | |
function sayHello() { | |
console.log(greeting); | |
} | |
sayHello(); // Prints "Hi there !" |
This file contains 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 myVariable = "Hi, I am a global variable"; | |
function sayHello() { | |
myVariable = "Hi, I am locally produced!"; | |
console.log(myVariable); | |
} | |
console.log(myVariable); // Prints "Hi, I am a global variable" | |
sayHello(); // Prints "Hi, I am locally produced!" | |
console.log(myVariable); // Prints "Hi, I am locally produced!" |
This file contains 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 myJob = "Developer"; | |
function showJob() { | |
var myJob = "Designer"; | |
console.log(myJob); | |
} | |
showJob(); // Prints "Designer" |
This file contains 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 myVariable = "global"; | |
printVariable(); // Prints "local" | |
function printVariable() { | |
var myVariable = "local"; | |
console.log(myVariable); | |
} | |
printVariable(); // Prints "local" |
This file contains 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 customer = { | |
firstName: "John", | |
lastName: "Doe", | |
greetCustomer: function(){ | |
// We use "this" instead of repeating "customer" | |
console.log("Hello again " + this.firstName + " " + this.lastName + "!"); | |
} | |
} | |
customer.greetCustomer(); // Prints "Hello again John Doe!" |