Insert cell
Insert cell
Insert cell
Insert cell
(param1, param2) => {
//code here
return 'something'
}
Insert cell
Insert cell
Insert cell
param => {
//code here
return 'something'
}
Insert cell
Insert cell
() => {
//code here
return 'something'
}
Insert cell
Insert cell
() => 'something'
Insert cell
Insert cell
Insert cell
func = function() {
return this.attr;
}
Insert cell
funcA = () => this.attr
Insert cell
objContext = ({
attr: 'objectAttribute',
objFunc: func,
objFuncA: funcA
})
Insert cell
objContext.objFunc()
Insert cell
objContext.objFuncA()
Insert cell
func.bind(objContext)()
Insert cell
funcA.bind(objContext)()
Insert cell
Insert cell
fortune = (type='random') => {
var fortunes = ['you will be happy', 'you will be sad', 'you will eat pineapple']
if(type==='happy')
return `Your ${type} fortune: ${fortunes[0]}`
else if(type==='sad')
return `Your ${type} fortune: ${fortunes[1]}`
else
return `Your ${type} fortune: ${fortunes[Math.floor(Math.random() * 3)]}`
}
Insert cell
fortune()
Insert cell
Insert cell
mysteryFunction = ({bob=5, joe=10, mary=30}={}) => {
//some long and complicated code nobody can read
return bob*joe*mary
}
Insert cell
mysteryFunction()
Insert cell
Insert cell
sum = (...thingsToSum) => thingsToSum.reduce((sum,val) => sum+val)
Insert cell
sum(1,2,3,4)
Insert cell
Insert cell
Insert cell
ex1 = {
var joe = function() {
return function(bob = 3, joe = 9, sam) {
if (bob && joe && sam) {
return function(joey) {
return "${joey} is a pie, la la la";
};
} else if (bob < joe) {
return function(joeDimagio) {
return "'My name is ${joeDimagio}, and a hopeful nation turns its eyes to meeee'`;
};
} else return `cool ${sam}`;
};
};
class Doggo {
constructor(a, b, c) {
this.a = a;
this.b = b;
this.c = c;
}

randfunc() {
return joe;
}
randfunc2(num === 5, { a === this.a, b == this.b, c === this.c } = {}) {
return num * a ** (b ** c);
}
}

return Doggo;
}
Insert cell
testCode(true, function() {
var ex = new ex1(1, 2, 3);
expect(ex.a).to.equal(1);
expect(ex.b).to.equal(2);
expect(ex.c).to.equal(3);

expect(ex.randfunc()()(1, 1, 1)('bob')).to.equal(`bob is a pie, la la la`);
expect(ex.randfunc()()()('bob')).to.equal(
`'My name is bob, and a hopeful nation turns its eyes to meeee'`
);
expect(ex.randfunc()()(0, 0, 'Sammy')).to.equal(`cool Sammy`);
expect(ex.randfunc2(6)).to.equal(6 * 1 ** (2 ** 3));
expect(ex.randfunc2(6, { a: 4 })).to.equal(6 * 4 ** (2 ** 3));
})
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more