// 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;
}
functionaddingNumbers(number1,number2){
returnnumber1+number2;
}
functionaddnums(1,2){
return3+5;
}
{
constmyConstantVar='world';//can't change a
letmyFirstVar='hello';//you can change b
myFirstVar='goodbye'
//myConstantVar = 'hi'
returnmyFirstVar
}
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="Wall-E"// Fill your name in here!
`hello, world, it's ${name}`
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]
functionaddthese(a,b){
returna+b;
}
typeof(addthese)
typeof(addthese(1,4))
"hello, world".toUpperCase()
margin=({top:500,bottom:200})
car=({
make:'Fiat',
model:500,
})
typeof(car.model)
car.model
directory={
constdata={"employees":[
{"firstName":"John","lastName":"Doe"},
{"firstName":"Anna","lastName":"Smith"},
{"firstName":"Peter","lastName":"Jones"}
]};
returndata
}
directory.employees
directory.employees[1]
directory.employees[1].firstName
directory.employees[2].lastName
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.