Published
Edited
Feb 13, 2019
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
console.log("Hello world");
// or
var helloMit = "Hello MIT";
console.log(helloMit);
}
Insert cell
Insert cell
Insert cell
Insert cell
height = 500

/*This is a
multiline
comment!*/
Insert cell
Insert cell
dimension = ({height, width})
Insert cell
width = 480
Insert cell
Insert cell
//dimension = {1000, 960}
Insert cell
Insert cell
// This block defines a cumulative sum of numbers from 0 to 10
{
let x = 0;
for (let i = 1; i <= 10; ++i) {
x += i;
}
return x;
}
Insert cell
Insert cell
x
Insert cell
Insert cell
function running_total(max) {
let x = 0;
for (let i = 1; i <= max; ++i)
x += i;
return x;
}


Insert cell
running_total(10)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
const a = 5;
a = 6;
return a;
}
Insert cell
Insert cell
{
let a = 5;
a = 6
return a;
}
Insert cell
Insert cell
Insert cell
1 + 2
Insert cell
typeof (1 + 2)
Insert cell
1.0 + 2.5
Insert cell
typeof (1.0 + 2.5)
Insert cell
2 / 0
Insert cell
typeof (2 / 0)
Insert cell
"a" / 2
Insert cell
typeof ("a" / 2)
Insert cell
Insert cell
"hello, world"
Insert cell
typeof "hello, world"
Insert cell
"hello, " + "world"
Insert cell
name = "" // Fill your name in here!
Insert cell
`hello, world, it's ${name}`

//need the ` at start and end to make line appear
Insert cell
typeof (`hello, world, it's ${name}`)
Insert cell
Insert cell
9 > 10
Insert cell
typeof (9 > 10)
Insert cell
10 == 10
Insert cell
Insert cell
(9 > 10) && (10 == 10) // Evaluates to false AND true
Insert cell
(9 > 10) || (10 == 10) // Evaluates to false OR true
Insert cell
!(9 > 10) && (10 == 10) // Evaluates to NOT(false) AND true
Insert cell
!((9 > 10) || (10 == 10)) // Evaluates to NOT(false or true)
Insert cell
Insert cell
Insert cell
typeof (x)
Insert cell
Insert cell
{ let y
return typeof (y)
}
Insert cell
Insert cell
ra = ["one", 2, 3.0]
Insert cell
typeof ra
Insert cell
ra[0]
Insert cell
ra[3]

//arrays are on RAM and so inconvenient for longer items.
//Thus for longer items, we use Generators which just take out the elements of an array that we need.
Insert cell
Insert cell
function addthese(a, b) {
return a+b;
}
Insert cell
typeof(addthese)
Insert cell
typeof(addthese(1, 4))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{\}
Insert cell
Insert cell
Insert cell
"hello, world".toUpperCase()
Insert cell
Insert cell
directory = {
const data = {"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]};
return data
}
Insert cell
directory_obj = ({
"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]
})
Insert cell
directory.employees
Insert cell
directory.employees[1]
Insert cell
directory.employees[1].firstName
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