Published
Edited
Sep 14, 2018
Insert cell
Insert cell
sumFunction = function(parameter1, parameter2, parameter3) {
// do some logic here
return parameter1 + parameter2 + parameter3;
}
Insert cell
Insert cell
// like so
result = sumFunction(1,2,3) // outputs 6
// we can set the result of the function to a variable so we can use it later
Insert cell
result
Insert cell
Insert cell
{
// save a function into a variable
const addOne = function( someNumber ) { return someNumber + 1 }
const multiplyByTwo = function ( someNumber ) { return someNumber*2 }
// we can copy a function into another variable
const copyOfAddOne = addOne
const doTwoThings = function ( number, process1, process2 ) {
const result1 = process1(number)
const result2 = process2(result1)
return result2;
}
// whats the difference between the values
const value1 = doTwoThings(5, addOne, multiplyByTwo)
const value2 = doTwoThings(5, multiplyByTwo, addOne)
const value3 = doTwoThings(5, copyOfAddOne, multiplyByTwo)


return [value1, value2, value3]
}
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