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
public class Test { | |
public static void main() { | |
System.out.println( "hello world" ); | |
} | |
} |
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
A Fairy Song | |
Over hill, over dale, | |
Thorough bush, thorough brier, | |
Over park, over pale, | |
Thorough flood, thorough fire! | |
I do wander everywhere, | |
Swifter than the moon's sphere; | |
And I serve the Fairy Queen, | |
To dew her orbs upon the green; |
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
ramsay = "chef"; // global variable 'ramsay' | |
function hellKitchen() { | |
knd = "chef"; // global variable 'knd' | |
} | |
function hellKitchen101() { | |
var chuckNorris = "chef"; // local variable 'chuckNorris' to this function | |
// watch out! this function 'assistant()' is locally scoped too |
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
function hellKitchen() { | |
if (true) { | |
var knd = "chef"; // will I be chef? | |
} | |
console.log(knd); // yes, I'm a chef due to variable hoisting | |
// and 'knd' is accessible anywhere in 'hellKitchen' | |
} | |
// equivalent snippet of code |
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
function hellKitchen() { | |
var knd = "chef"; | |
function hellKitchen101() { | |
console.log(knd); | |
knd = "assistant"; | |
} | |
hellKitchen101(); | |
console.log(knd); // I'm now an 'assistant' |
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
function cook() { | |
console.log(this); // 'this' is 'Window' | |
// the default global object of Chrome | |
function prepare() { | |
console.log(this); // 'this' is also 'Window' | |
} | |
prepare(); | |
} | |
var cook101 = function() { |
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
hellKitchen = { | |
cook: function() { | |
console.log(this); | |
} | |
} | |
hellKitchen.cook(); // the context 'this' is 'hellKitchen' Object |
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
hellKitchen = { | |
cook: function() { | |
console.log(this); | |
} | |
} | |
myKitchen = { | |
knd: "amateur chef" |
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
function HellKitchen() { | |
console.log(this); | |
this.cook = function() { | |
console.log(this); | |
}; | |
} | |
k = new HellKitchen(); | |
k.cook(); |
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
hellKitchen = { | |
cook: function(cb) { | |
cb(); | |
} | |
} | |
myKitchen = { | |
knd: function() { | |
console.log(this); | |
} |
OlderNewer