Published
Edited
Feb 13, 2019
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
/*this is a multiline comment
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

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
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
function addingNumbers(number1, number2){
return number1 + number2
}
Insert cell
addingNumbers(1,'this')
Insert cell
running_total(10)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
const a = 5;
a = 6;
return a;
}
Insert cell
//let allows you to create a new variable from scratch
//const is different from let in that const you cannot change over time
{
let myFirstVar = 'hello'
const myConstantVar='world'
myFirstVar= 'goodbye'
myConstantVar= 'hi'
}
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 = "Carolyn" // Fill your name in here!
Insert cell
`hello, world, it's ${name}`
Insert cell
typeof (`hello, world, it's ${name}`)
Insert cell
`today is ${day}`
Insert cell
day = "wednesday"
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]
Insert cell
//can look at any given element of array to see property
Insert cell
Insert cell
function addthese(a, b) {
return a+b;
}
Insert cell
//how to dispose of elements you're not using
Insert cell
typeof(addthese)
Insert cell
typeof(addthese(1, 4))
Insert cell
Insert cell
Insert cell
//syntax for an object
car=({
make: 'Fiat',
model: '500'
})
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.employees
Insert cell
directory.employees[1]
Insert cell
directory.employees[2].firstName
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