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
// sometimes used as lowercase as when setting up your server. | |
const express = require(‘express’); | |
const app = express(); | |
// sometimes uppercase. | |
const DONT_CHANGE_ME_MAN = “I ain’t changing for no one, man.” | |
// change attempt #1 | |
const DONT_CHANGE_ME_MAN = “I told I ain’t changing for no one.” | |
// change attempt #2 |
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
// When using var what do we get? | |
var bunny = "eat carrot"; | |
if(bunny) { | |
var bunny = "eat twig"; | |
console.log(bunny) // "eat twig" | |
} | |
console.log(bunny)// "eat twig" |
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
// with var. See example live: https://jsfiddle.net/maasha/gsewf5av/ | |
for(var i= 0; i<30; i++){ | |
var div = document.createElement('div'); | |
div.onclick = function() { | |
alert("you clicked on a box " + i); | |
}; | |
document.getElementsByTagName('section')[0].appendChild(div); | |
} | |
// with let. See example live: https://jsfiddle.net/maasha/xwrq8d5j/ |
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
// Test it here: https://jsfiddle.net/maasha/x7wz1686/ | |
var bunny = { | |
name: 'Usagi', | |
showName: function() { | |
alert(this.name); | |
} | |
}; | |
bunny.showName(); // Usagi |
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
// Test it here: https://jsfiddle.net/maasha/z65c1znn/ | |
var bunny = { | |
name: 'Usagi', | |
tasks: ['transform', 'eat cake', 'blow kisses'], | |
showTasks: function() { | |
this.tasks.forEach(function(task) { | |
alert(this.name + " wants to " + task); | |
}); | |
} | |
}; |
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
// Test it here: https://jsfiddle.net/maasha/g278gjtn/ | |
var standAloneFunc = function(){ | |
alert(this); | |
} | |
standAloneFunc(); // [object Window] |
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
// Test it here: https://jsfiddle.net/maasha/3mu5r6vg/ | |
var bunny = { | |
name: 'Usagi', | |
tasks: ['transform', 'eat cake', 'blow kisses'], | |
showTasks: function() { | |
var _this = this; | |
this.tasks.forEach(function(task) { | |
alert(_this.name + " wants to " + task); | |
}); | |
} |
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
// Test it here: https://jsfiddle.net/maasha/u8ybgwd5/ | |
var bunny = { | |
name: 'Usagi', | |
tasks: ['transform', 'eat cake', 'blow kisses'], | |
showTasks: function() { | |
this.tasks.forEach(function(task) { | |
alert(this.name + " wants to " + task); | |
}.bind(this)); | |
} | |
}; |
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
// Test it here: https://jsfiddle.net/maasha/che8m4c1/ | |
var bunny = { | |
name: 'Usagi', | |
tasks: ['transform', 'eat cake', 'blow kisses'], | |
showTasks() { | |
this.tasks.forEach((task) => { | |
alert(this.name + " wants to " + task); | |
}); | |
} |
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
// Before | |
let bunny = function(name) { | |
console.log("Usagi"); | |
} | |
// After | |
let bunny = (name) => console.log("Usagi") | |
// Step 1: Remove the word ‘function’. | |
let bunny = (name) { |
OlderNewer