// This block defines a cumulative sum of numbers from 0 to 10
{
letx=0;
for(leti=1;i<=10;++i){
x+=i;
}
returnx;
}
x
functionrunning_total(max){
letx=0;
for(leti=1;i<=max;++i)
x+=i;
returnx;
}
running_total(10)
{
consta=5;
a=6;
returna;
}
{
leta=5;
a=6
returna;
}
1+2
typeof(1+2)
1.0+2.5
typeof(1.0+2.5)
2/0
typeof(2/0)
"a"/2
typeof("a"/2)
"hello, world"
typeof"hello, world"
"hello, "+"world"
name=""// Fill your name in here!
`hello, world, it's ${name}`
//need the ` at start and end to make line appear
typeof(`hello, world, it's ${name}`)
9>10
typeof(9>10)
10==10
(9>10)&&(10==10)// Evaluates to false AND true
(9>10)||(10==10)// Evaluates to false OR true
!(9>10)&&(10==10)// Evaluates to NOT(false) AND true
!((9>10)||(10==10))// Evaluates to NOT(false or true)
typeof(x)
{lety
returntypeof(y)
}
ra=["one",2,3.0]
typeofra
ra[0]
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.
functionaddthese(a,b){
returna+b;
}
typeof(addthese)
typeof(addthese(1,4))
{\}
"hello, world".toUpperCase()
directory={
constdata={"employees":[
{"firstName":"John","lastName":"Doe"},
{"firstName":"Anna","lastName":"Smith"},
{"firstName":"Peter","lastName":"Jones"}
]};
returndata
}
directory_obj=({
"employees":[
{"firstName":"John","lastName":"Doe"},
{"firstName":"Anna","lastName":"Smith"},
{"firstName":"Peter","lastName":"Jones"}
]
})
directory.employees
directory.employees[1]
directory.employees[1].firstName
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.