Public
Edited
Aug 24, 2022
Insert cell
Insert cell
Insert cell
Insert cell
a = 6
Insert cell
b = 4
Insert cell
a * b
Insert cell
Insert cell
// Strings / Text
"Hello World"
Insert cell
// Variable = Value
x = 2
Insert cell
### 3. Boolean
Insert cell
true
Insert cell
// Boolean
x === 1
Insert cell
Insert cell
// Array
country = ["india", "pakistan", "srilanka"]
Insert cell
// Access the array is [index]
// Index start from 0
country[0]
Insert cell
Insert cell
// Object
// Key - Value Pair
countryShort = ({ india: "IN", pakistan: "PK", srilanka: "SL" })
Insert cell
countryShort.india
Insert cell
countryStates = ({ india: ["KAR", "JK", "TN"], pakistan: "PK", srilanka: "SL" })
Insert cell
countryStates.india
Insert cell
Insert cell
m = "hello"
Insert cell
// Built in Function
m.toUpperCase()
Insert cell
function sum(a, b) {
return a + b;
}
Insert cell
sum(x, 50)
Insert cell
function doubleSum(a, b) {
return sum(a, b) + sum(a, b);
}
Insert cell
doubleSum(x, 2)
Insert cell
// Arrow Function - Short Form of writing a function
// function tripleMult(d) {return 3 * d}
tripleMult = (d) => 3 * d
Insert cell
tripleMult(2)
Insert cell
(d) => d * 3
Insert cell
digits = [1, 2, 3]
Insert cell
digits.map((d) => d * 3)
Insert cell
digits.map(tripleMult)
Insert cell
// For Loop
{
let sum = 0;
for (let step = 0; step < 10; step++) {
sum = sum + step;
}
return sum;
}
Insert cell
// Columns Way
dataColumns = ({
area: ["north", "east", "west", "south", "central"],
sales: [5, 15, 10, 20, 15],
profit: [2, 8, 6, 5, 3]
})
Insert cell
// Row Way
dataRow = [
{ area: "north", sales: 5, profit: 2 },
{ area: "east", sales: 25, profit: 8 },
{ area: "west", sales: 10, profit: 6 },
{ area: "south", sales: 20, profit: 5 },
{ area: "central", sales: 15, profit: 3 }
]
Insert cell
Insert cell
url = "https://docs.google.com/spreadsheets/d/e/2PACX-1vTPCMJ8uhkpU11KCRyov3p0uy5Tazcumq-al0HcMx-4fx3cvxZTYJ2WBqy5yGZUFoDo8TK5BC-4rS-c/pub?gid=0&single=true&output=csv"
Insert cell
d3.csv(url, d3.autoType)
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

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