Published
Edited
May 23, 2021
Insert cell
Insert cell
Insert cell
"hello" === 'hello'
Insert cell
Insert cell
myName = 'Dan'
Insert cell
`Hello, ${myName}! Your name has ${myName.length} letters.`
Insert cell
`3 x 4 = ${3 * 4}`
Insert cell
Insert cell
roster = ['Sue', 'Bob', 'Joe', 'Meg', 'Michelle', 'Mike', 'Kate', 'Sue', 'Mike', 'Meg', 'Joe']
Insert cell
roster.length
Insert cell
roster[0]
Insert cell
roster[roster.length - 1]
Insert cell
roster.slice(1, 4)
Insert cell
Insert cell
uniqueNames = new Set(roster)
Insert cell
uniqueNames.size
Insert cell
Insert cell
uniqueNames.has('Sue')
Insert cell
uniqueNames.has('Brad')
Insert cell
Insert cell
{
const classes = new Set();
classes.add('Information Visualization');
classes.add('Algorithms');
classes.add('Machine Learning');
classes.delete('Algorithms');
return classes;
}
Insert cell
Insert cell
stringToInt = ({
'one': 1,
'two': 2,
'three': 3
})
Insert cell
Insert cell
stringToInt.one
Insert cell
stringToInt['one']
Insert cell
Insert cell
stringToInt.hasOwnProperty('two')
Insert cell
stringToInt.hasOwnProperty('four')
Insert cell
Insert cell
stringToInt['four']
Insert cell
Insert cell
Object.fromEntries([
['one', 1],
['two', 2],
['three', 3],
])
Insert cell
Insert cell
Object.entries(stringToInt)
Insert cell
Insert cell
{
const nameToScore = {};
nameToScore['Tim'] = 100;
nameToScore['Becky'] = 95;
nameToScore.Jill = 90;
nameToScore.Ben = 85;
delete nameToScore.Becky;
delete nameToScore['Tim'];
return nameToScore;
}
Insert cell
Insert cell
nameToAge = new Map([
['Bob', 20],
['Sue', 25],
['Joe', 30],
['Jen', 35]
])
Insert cell
new Map(Object.entries(stringToInt))
Insert cell
Insert cell
nameToAge.has('Jen')
Insert cell
nameToAge.has('Ted')
Insert cell
nameToAge.get('Jen')
Insert cell
nameToAge.get('')
Insert cell
Insert cell
{
const nameToScore = new Map();
nameToScore.set('Tim', 100);
nameToScore.set('Becky', 95);
nameToScore.set('Jill', 90);
nameToScore.set('Ben', 85);
nameToScore.delete('Becky');
nameToScore.delete('Tim');
return nameToScore;
}
Insert cell
Insert cell
Array.from(nameToAge)
Insert cell
Insert cell
Object.fromEntries(Array.from(nameToAge))
Insert cell
Insert cell
function greeting(name) {
return `Hello, ${name}!`;
}
Insert cell
greeting('Dan')
Insert cell
Insert cell
farewell = name => `Good bye, ${name}!`
Insert cell
farewell('Dan')
Insert cell
Insert cell
exponent = (base, power) => base ** power
Insert cell
exponent(3, 2)
Insert cell
Insert cell
double = num => {
const value = num * 2;
return `${num} doubled is ${value}`;
}
Insert cell
double(10)
Insert cell
Insert cell
makePerson = (name, age) => ({
name: name,
age: age
})
Insert cell
makePerson('Jill', 30)
Insert cell
Insert cell
makePerson2 = (name, age) => ({
name,
age
})
Insert cell
makePerson2('Jill', 30)
Insert cell
Insert cell
makePerson3 = (name, age) => {
return { name, age };
}
Insert cell
makePerson3('Jill', 30)
Insert cell
Insert cell
nameToAge
Insert cell
Array.from(nameToAge)
Insert cell
Insert cell
Array.from(nameToAge, pair => pair)
Insert cell
Insert cell
Array.from(nameToAge, pair => `${pair[0]} is ${pair[1]} years old.`)
Insert cell
Insert cell
Array.from(nameToAge, pair => ({ name: pair[0], age: pair[1] }) )
Insert cell
Insert cell
Array.from(nameToAge, pair => ({ name: pair[0], age: pair[1] }) )
Insert cell
Insert cell
Array.from(nameToAge, ([name, age]) => ({ name: name, age: age}))
Insert cell
Insert cell
Array.from(nameToAge, ([name, age]) => ({ name, age }))
Insert cell
Insert cell
Array.from(nameToAge, function(pair) {
return {
name: pair[0],
age: pair[1]
};
})
Insert cell
Insert cell
function personToString1(person) {
return `${person.name} is ${person.age} years old and attends ${person.school}.`;
}
Insert cell
function personToString2({ name, age, school }) {
return `${name} is ${age} years old and attends ${school}.`;
}
Insert cell
person = ({ name: 'Chris', age: 22, school: 'NYU'})
Insert cell
personToString1(person)
Insert cell
personToString2(person)
Insert cell
Insert cell
{
const coordinate = [10, 20];
const [x, y] = coordinate;
return x + y;
}
Insert cell
{
const coordinate = { x: 10, y: 20 };
const {x, y} = coordinate;
return x + y;
}
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