Published
Edited
Sep 14, 2021
46 forks
93 stars
Insert cell
Insert cell
Insert cell
42
Insert cell
Insert cell
6.022e23 // holy mole-y
Insert cell
Insert cell
+"1.23"
Insert cell
Insert cell
+"Am I a number?"
Insert cell
Insert cell
isNaN(1 / 'monkey boots')
Insert cell
Insert cell
(1 + Math.sqrt(5)) / 2 // a φ-nominal number
Insert cell
Insert cell
Math.random()
Insert cell
Insert cell
true
Insert cell
!false
Insert cell
!0
Insert cell
Insert cell
false
Insert cell
!true
Insert cell
!1
Insert cell
Insert cell
true || false
Insert cell
Insert cell
true && false
Insert cell
Insert cell
2 + 2 === 4
Insert cell
2 + 2 !== "jello"
Insert cell
Insert cell
2 < 1
Insert cell
4 >= 3 + 1
Insert cell
"I" < "you" // whoa
Insert cell
Insert cell
1 == "1"
Insert cell
"1" + 1 == 11
Insert cell
Insert cell
"1" + 1 === 11
Insert cell
Insert cell
"I am a string."
Insert cell
Insert cell
'I am also a string.'
Insert cell
Insert cell
"I am conflicted.'
Insert cell
Insert cell
"0123456789".length
Insert cell
Insert cell
'better' + ' together'
Insert cell
Insert cell
`A backtick-quoted (\`) string with ${'javascript'.toUpperCase() + ' code'} inside it.`
Insert cell
Insert cell
"STOP SHOUTING!".toLowerCase()
Insert cell
' white space surrounds me '.trim() + '?'
Insert cell
Insert cell
"slice".slice(2) // slice from the left
Insert cell
"dice".slice(-3) // now slice from the right
Insert cell
"baby".slice() // now turn it out
Insert cell
Insert cell
"comma,separated,values".split(',')
Insert cell
Insert cell
Insert cell
array = ['a', 'b', 'c']
Insert cell
array.length
Insert cell
array[0] // first element
Insert cell
array[1] // second element
Insert cell
array[2] // third element
Insert cell
array[3] // oops
Insert cell
array[-1] // oops, I did it again
Insert cell
Insert cell
array.indexOf('b') // find the first instance, from the left
Insert cell
array.slice(1) // slice from the left
Insert cell
array.slice(-2) // now slice from the right
Insert cell
array.slice(1, -1) // now slice from both sides
Insert cell
array.join(' -> ') // turn an array into a string
Insert cell
array.concat('d') // combine values into a new array
Insert cell
'I put my thing down split it and reverse it'.split('').reverse().join('')
Insert cell
Insert cell
object = ({key: "value", anotherKey: "anotherValue"})
Insert cell
Insert cell
Insert cell
object.key
Insert cell
object.anotherKey
Insert cell
Insert cell
Object.keys(object) // return an array of property key strings
Insert cell
Insert cell
Object.values(object) // return an array of property values
Insert cell
Insert cell
Object.assign({target: 'me', value: 0}, {source: 'thing1', value: 1}, {source: 'thing2'})
Insert cell
Insert cell
data = [
{city: "Seattle", annual_hours_sunshine: 2163, annual_precipitation: 37.13},
{city: "New York", annual_hours_sunshine: 2677, annual_precipitation: 46.23},
{city: "Chicago", annual_hours_sunshine: 2504, annual_precipitation: 39.04}
]
Insert cell
Insert cell
function addMe(a, b) { // function signature: name and input arguments
return a + b; // function body, with return statement for output
}
Insert cell
Insert cell
addMe(2, 2)
Insert cell
addMe('better', ' together')
Insert cell
addMe(1, '1') // wat?
Insert cell
addMe('💕', 'U', '😍') // sorry heart-eyes, extra arguments are ignored
Insert cell
Insert cell
addMe('1') // something from nothing
Insert cell
addMe() // undefined + undefined is not a number
Insert cell
Insert cell
addMe2 = (a, b) => a + b
Insert cell
addMe2(2, 2)
Insert cell
Insert cell
precip = d => d.annual_precipitation
Insert cell
precip(data[0]) // emerald city
Insert cell
precip(data[1]) // yr city's a sucker
Insert cell
Insert cell
Insert cell
data // expand the inspector above to see the values
Insert cell
Insert cell
hoursPerYear = 365 * 24 // yes yes, but let's ignore leap years for now
Insert cell
data.map(d => d.annual_hours_sunshine / hoursPerYear) // d is for datum
Insert cell
Insert cell
Insert cell
data.filter(d => d.annual_precipitation < 40).map(d => d.city)
Insert cell
Insert cell
Insert cell
Insert cell
'hello cell'
Insert cell
Insert cell
retort = 'hello yourself'
Insert cell
Insert cell
md`Markdown includes _italicized_, **bold**, and \`monospace\` text, as well as [hyperlinks](https://www.youtube.com/watch?v=xfr64zoBTAQ).

- Oh, and of course lists.
- We musn't ever forget,
- the lists.

`
Insert cell
Insert cell
tex`i\hbar \frac{\partial \Psi}{\partial t} = -\frac{\hbar^2}{2m}
\frac{\partial^2 \Psi}{\partial x^2} + V \Psi` // how's your cat?
Insert cell
Insert cell
`You said "${retort}"`
Insert cell
Insert cell
Insert cell
viewof slider = html`<input type="range" value=42 min=0 max=100 step=1></input>`
Insert cell
Insert cell
tex`f(x) = x^2 \rightarrow f(${slider}) = ${slider}^2 = ${slider * slider}`
Insert cell
Insert cell
result = {
const myConstant = '_How do I love thee?_ Let me count the ways: ';
let myVariable = [];
// you didn't think you'd make it to the end without a for loop, did you?
for (let i = 0; i < 3; ++i) {
// push adds an element to an array, updating it in place
myVariable.push(`**${i + 1}...**`);
}
// you can use tagged templates anywhere!
return md`${myConstant + myVariable.join(' ')}`;
}
Insert cell
Insert cell
Insert cell
Insert cell
d3 = require('d3-array')
Insert cell
d3.mean(data, d => d.annual_precipitation)
Insert cell
d3.min(data, d => d.annual_precipitation)
Insert cell
d3.max(data, d => d.annual_precipitation)
Insert cell
Insert cell
import {printTable} from '@uwdata/data-utilities'
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more