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 d = new Date(); | |
var d = new Date(milliseconds); | |
var d = new Date(dateString); | |
var d = new Date(year, month, day [,hour,minute,second,millisecond ]); |
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
for (var i = 0; i < 10; i++) { | |
(function (j) { | |
setTimeout(function() { | |
console.log(j); | |
}, j*1000); | |
})(i); | |
} |
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
for (var i = 0; i < 10; i++) { | |
function timer(j) { | |
setTimeout(function() { | |
console.log(j); | |
}, j*1000); | |
}; | |
timer(i); | |
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
for (var i = 0; i < 10; i++) { | |
console.log(i); | |
setTimeout(function() { | |
console.log(i); | |
}, i*1000); | |
} |
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 bakeCake(ingredient){ | |
// Code that adds the ingredient to the cake batter | |
console.log(ingredient+ ' cake : add ' +ingredient+ ' to the batter'); | |
function ovenTemperature(temperature, time){ | |
// Code that sets the right temperature for baking the cake | |
console.log('Set the oven temperature to ' +temperature+' and ready to bake the '+ingredient+' cake for ' +time+ ' minutes'); | |
} | |
return ovenTemperature; | |
} |
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
console.log(myFunction()); | |
// Prints | |
function add(number2) { | |
return number1 + number2; | |
} |
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 myFunction(number1) { | |
function add(number2) { | |
/* The number1 variable is accessible from this function, | |
because number1 has been defined outside of the add function */ | |
return number1 + number2; | |
} | |
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
for (var i = 0; i < 10; i++) { | |
setTimeout(function() { | |
console.log(i); | |
}, i*1000); | |
} |
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(){ | |
console.log("Hello again " + this.firstName + " " + this.lastName + "!"); | |
function nestedFunction(){ | |
console.log(this); | |
} | |
nestedFunction(); |
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 cat = "Alphonse"; | |
// The variable cat is actually attached to the global window object : | |
console.log(window.cat === cat); // Prints true | |
// "this" in the global context has the value of the global window object | |
console.log(this); // Prints the window object |
NewerOlder