Published
Edited
Dec 29, 2018
Insert cell
Insert cell
sum = (a, b) => a + b
Insert cell
sum(1, 2)
Insert cell
sum(10e4, 5)
Insert cell
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
x = 10
Insert cell
square = a => a * a
Insert cell
square(12)
Insert cell
Insert cell
greeting = `Hey ${name}, how are you?`
Insert cell
Insert cell
Insert cell
greet = name => `Hola ${name}, que pasa?`
Insert cell
greet(`Rafic`)
Insert cell
Insert cell
Insert cell
Insert cell
numbers = [1, 2, 3, 4]
Insert cell
names = ["leti", "dennis", "rafic"]
Insert cell
names[0]
Insert cell
md`### Objects / Maps / Dictionary`
Insert cell
phoneBook = ({
leti: "+16479992080",
rafic: "+16107169757"
})
Insert cell
phoneBook["leti"]
Insert cell
arrayAsMap = ({ 0: "leti", 1: "rafic", 3: "Dennis" })
Insert cell
Insert cell
Insert cell
html`<h1 style=background:red>Hello</h2>`
Insert cell
hiccup([
"div",
["h1", { style: { background: "lightgreen" } }, "shopping list"],
["div", ["input", { type: "checkbox" }], ["label", shoppingList[0]]],
["div", ["input", { type: "checkbox" }], ["label", shoppingList[1]]],
["div", ["input", { type: "checkbox" }], ["label", shoppingList[2]]]
])
Insert cell
shoppingListItem = async (item, translateOpts) => {
if (translateOpts) {
item = await translate({
source: translateOpts.source,
target: translateOpts.target,
text: item
}).then(x => x.translatedText);
}
return [
"div",
{ style: { color: "tomato" } },
["input", { type: "checkbox" }],
["label", item]
];
}
Insert cell
shoppingList = [
"kiwis",
"avocados",
"banana",
"apples",
"pears",
"cucumber",
"spaghetti",
"garlic"
]
Insert cell
{
return hiccup([
"div",
["h1", { style: { background: "lightgreen" } }, "shopping list"],

await Promise.all(
shoppingList.map(item =>
shoppingListItem(item, { source: "en", target: "it" })
)
)
]);
}
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