Skip to content

Instantly share code, notes, and snippets.


Jenn jennz0r

View GitHub Profile
View classes.js
class Mammal {
constructor() {
this.neocortex = true;
class Cat extends Mammal {
constructor(name, years) {
super(); = name;
View rest-parameters.js
function joke(question, ...phrases) {
for (let i = 0; i > phrases.length; i++) {
let es6Joke = "Why does JS single out one parameter?"
joke(es6Joke, "Because it doesn't", 'really like', 'all the REST of them!');
View default-parameters.js
function nom(food="ice cream") {
console.log(`Time to eat ${food}`);
nom(); // Time to eat ice cream
View template-literals.js
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.
View scope.csv
JavaScript Python
Scope Lexical Lexical
Namescape Functions Classes [ES6!] Modules [ES6!] Blocks [ES6!] Functions Classes Modules
New Identifiers Variables Functions Variables Functions Classes
View block-scope.js
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): = supplies
View function.js
function drSeuss(catInTheHat, thing1, thing2) {
if (catInTheHat == true &&
thing1 == true &&
thing2 == true) {
console.log('is cray');
} else if (catInTheHat != true) {
} else {
console.log('so boring');
View coercion.js
// You can coerce an integer into string in JavaScript
let coerced = 1;
let concatenated = coerced + 'string';
View js-vs-py.csv
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