Skip to content

Instantly share code, notes, and snippets.

View lenafaure's full-sized avatar

Lena Faure lenafaure

View GitHub Profile
var map;
var infowindow;
var searchwords = "agence+web";
// Initiate Map
function initMap() {
var paris = {lat: 48.8704907, lng: 2.3309359};
map = new google.maps.Map(document.getElementById('map'), {
center: paris,
@lenafaure
lenafaure / local_global_scope.js
Last active July 5, 2017 13:21
Local and global variable scope
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"
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;
}
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 ]);
for (var i = 0; i < 10; i++) {
(function (j) {
setTimeout(function() {
console.log(j);
}, j*1000);
})(i);
}
for (var i = 0; i < 10; i++) {
function timer(j) {
setTimeout(function() {
console.log(j);
}, j*1000);
};
timer(i);
for (var i = 0; i < 10; i++) {
console.log(i);
setTimeout(function() {
console.log(i);
}, i*1000);
}
console.log(myFunction());
// Prints
function add(number2) {
return number1 + number2;
}
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;
}
for (var i = 0; i < 10; i++) {
setTimeout(function() {
console.log(i);
}, i*1000);
}