Public
Edited
Mar 2, 2023
1 fork
35 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Look at me, I’m <mark>marked text</mark>!
Insert cell
<style>
mark {
background-color: cyan;
}
</style>
Insert cell
Insert cell
Insert cell
Insert cell
array = [0, 1, 2, 3, 4]
Insert cell
array // Bad: nondeterministic order
Insert cell
array.reverse() // Bad: mutates array
Insert cell
Insert cell
Insert cell
Insert cell
array2 = [0, 1, 2, 3, 4]
Insert cell
array2.slice().reverse() // Good: copy before mutate
Insert cell
{
const array3 = [0, 1, 2, 3, 4];
array3.reverse(); // Good: mutation local to cell
return array3;
}
Insert cell
Insert cell
Insert cell
require("he") // Danger: loads the latest version of he, whatever that is!
Insert cell
require("he@1") // Good: pinned major version
Insert cell
require("he@1.2.0") // Also good: pinned exact version
Insert cell
require("he@1.2.0/he.js") // Also good: pinned exact version and path
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
// When this cell is re-run, mark the old object as dead.
const object = {alive: true};
invalidation.then(() => object.alive = false);
return object;
}
Insert cell
{
for (let i = 0; true; ++i) {
yield i;
}
}
Insert cell
Insert cell
Insert cell
foo = htl.html`<div>foo</div>`
Insert cell
foo.textContent // Good: explicit reference to foo
Insert cell
Insert cell
htl.html`<div id=bar>bar</div>`
Insert cell
document.querySelector("#bar") // Bad: implicit reference to bar
Insert cell
Insert cell
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