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
class Mammal { | |
constructor() { | |
this.neocortex = true; | |
} | |
} | |
class Cat extends Mammal { | |
constructor(name, years) { | |
super(); | |
this.name = 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
function joke(question, ...phrases) { | |
console.log(question); | |
for (let i = 0; i > phrases.length; i++) { | |
console.log(phrases[i]); | |
} | |
} | |
let es6Joke = "Why does JS single out one parameter?" | |
joke(es6Joke, "Because it doesn't", 'really like', 'all the REST of them!'); | |
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 nom(food="ice cream") { | |
console.log(`Time to eat ${food}`); | |
} | |
nom(); // Time to eat ice cream |
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
let exclamation = 'Whoa!'; | |
let sentence = `They are really similar to Python.`; | |
console.log(`Template Literals: ${exclamation} ${sentence}`); | |
// Template Literals: Whoa! They are really similar to Python. |
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
JavaScript | Python | ||
---|---|---|---|
Scope | Lexical | Lexical | |
Namescape | Functions Classes [ES6!] Modules [ES6!] Blocks [ES6!] | Functions Classes Modules | |
New Identifiers | Variables Functions | Variables Functions Classes |
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 simpleExample(value) { | |
if (value) { | |
var varValue = value; | |
let letValue = value; | |
console.log(varValue, letValue); // value value | |
} | |
// varValue is available even though it was defined | |
// in if-block because it was "hoisted" to function scope | |
console.log(varValue); // value |
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
def fish_and_chips(): | |
ingredients = ['fish', 'potatoes', 'batter'] | |
print 'cooking %s together' % (', '.join(ingredients)) | |
# cooking fish, potatoes, batter | |
class Baking(object): | |
def __init__(self, supplies): | |
self.supplies = supplies |
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 drSeuss(catInTheHat, thing1, thing2) { | |
if (catInTheHat == true && | |
thing1 == true && | |
thing2 == true) { | |
console.log('is cray'); | |
} else if (catInTheHat != true) { | |
console.log('boring'); | |
} else { | |
console.log('so boring'); | |
} |
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
// You can coerce an integer into string in JavaScript | |
let coerced = 1; | |
let concatenated = coerced + 'string'; |
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
JavaScript | Python | ||
---|---|---|---|
Boolean | true false | True False | |
Nothing | null | None | |
Empty Value | undefined |