Published
Edited
Nov 18, 2018
1 star
Insert cell
Insert cell
Insert cell
Insert cell
eight = 3 + 5 // addition
Insert cell
zeroPointThree = 0.1 + 0.2 // floating point addition
Insert cell
five = 8 - 3 // subtraction
Insert cell
twenty = 10 * 2 // multiplication
Insert cell
seven = 42 / 6 // division
Insert cell
Insert cell
fifteen = eight + seven
Insert cell
Insert cell
myString = "Hello World"
Insert cell
myString + ", This gets concatenated!" // combine strings
Insert cell
myString.substring(0,5) // takes the characters at 0 through 4
Insert cell
Insert cell
Insert cell
"same thing" == "same thing" // == checks if equal
Insert cell
"I'm not" != "the same" // != checks if not equal
Insert cell
3 <= 4 // <= less than or equal to
Insert cell
4 >= 3 // >= greater than or equal to
Insert cell
!false // ! negates a value
Insert cell
("we" != "can") && ("combine" != "these") // && does two comparisons and sees if theyre both true
Insert cell
0 == 1 || 8 == 8 // || checks if one of them is true
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
if( myObj.myNumber == 123 ) {
return "myObj.myNumber is actually 123!"
}
}
Insert cell
Insert cell
{
let num = 0;
while(true) {
await wait(1000)
yield md`Seconds since you opened this page: ${num++}`;
}
}
Insert cell
{
let colorsOfTheRainbow = [ "red", "orange", "yellow", "green", "blue", "indigo", "violet" ]
let allColors = ""
for( let i = 0; i<colorsOfTheRainbow.length; i++) {
allColors+= "A color of the rainbow is " + colorsOfTheRainbow[i] + ". ";
}
return allColors
}
Insert cell
Insert cell
Insert cell
function sleepIn(weekday, vacation) {
return true;
}
Insert cell
Insert cell
function hasTeen(num1, num2, num3) {
return false;
}
Insert cell
Insert cell
function front3(str) {
return "";
}
Insert cell
Insert cell
function everyNth(str, num) {

return "";
}

Insert cell
Insert cell
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