Skip to content

Instantly share code, notes, and snippets.

View jennz0r's full-sized avatar
🍦
.

Jenn jennz0r

🍦
.
View GitHub Profile
class Mammal {
constructor() {
this.neocortex = true;
}
}
class Cat extends Mammal {
constructor(name, years) {
super();
this.name = name;
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!');
function nom(food="ice cream") {
console.log(`Time to eat ${food}`);
}
nom(); // Time to eat ice cream
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.
JavaScript Python
Scope Lexical Lexical
Namescape Functions Classes [ES6!] Modules [ES6!] Blocks [ES6!] Functions Classes Modules
New Identifiers Variables Functions Variables Functions Classes
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
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
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');
}
// You can coerce an integer into string in JavaScript
let coerced = 1;
let concatenated = coerced + 'string';
JavaScript Python
Boolean true false True False
Nothing null None
Empty Value undefined
Number Number int float long complex
Sequences Array list tuple bytearray buffer xrange
Key Value Store Object Dictionary