Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
var bob = {name: "Bob", emotion: "happy", species: "Hooman"}
return bob
}
Insert cell
Insert cell
{
var bob = {
name: 'Mr. Bobz',
caffeinated: true
}
return bob.name
}
Insert cell
Insert cell
{
var bob = {name: "Bob", emotion: "Hangry", eat: "Om nom nom"}
return eat
}
Insert cell
{
var bob = {name: "Bob", emotion: "Hangry", eat: "Om nom nom"}
return bob.eat
}
Insert cell
{
var bob = {name: "Bob", emotion: "Hangry", eat: "Om nom nom"}
return bob.someMissingKey
}
Insert cell
Insert cell
// DECLARAING A FUNCTION
function myFunctionThatCalculatesASum( parameter1, parameter2 ) {
// CODE BLOCK: do stuff in here
var sumOfMyParamters = parameter1 + parameter2
return sumOfMyParamters // <-- this is outputted from the function
}
Insert cell
// RUNNNING THE FUNCTION
theOutput = myFunctionThatCalculatesASum(20,22)
Insert cell
{
function sum(a,b) {
return a + b
}
function product(a,b) {
return a * b
}
var onePlusTwo = sum(1,2)
var threePlusFour = sum(3,4)
var productOfTwoVariables = product(onePlusTwo, threePlusFour)
return productOfTwoVariables // <-- ignore that return. it's to make the notebook work
}
Insert cell
Insert cell
function cookPizza(rawPizza) {
return "cooked " + rawPizza
}
Insert cell
cookPizza("mushroom pizza")
Insert cell
cookPizza("wings")
Insert cell
Insert cell
typeof function bob() {}
Insert cell
Insert cell
{
var bob = function () {return "Hi, I'm in Bob!"}
var joe = bob() + " And now I'm called by Joe!"
return joe
}
Insert cell
Insert cell
{
var exampleObject = {
name: 'example',
func: function() {
return "hi!"
}
}
return exampleObject
}
Insert cell
Insert cell
{
var bob = {
name: 'bobz',
hangry: false,
eat: function() {
return hangry;
}
}
return bob.eat()
}
Insert cell
Insert cell
{
var bob = {
name: "Bob",
emotion: "Hangry",
eat: function() {
this.emotion = "Full"
}}
bob.eat()
return bob.emotion
}
Insert cell
Insert cell
thisOutOfContext = function() {
// what could `this` be?
return this;
}
Insert cell
Insert cell
{
var doggo = {
bark: function() {
return this.sound
},
sound: 'wooof!'
}
var doggoII = {
bark: doggo.bark,
sound: 'not wooof!'
}
return doggo.bark()
}
Insert cell
Insert cell
Insert cell
Insert cell
function jerry() {
return {
//debug starting here
name: 'Jerry'
superpower = 'intelligence'
powerScore: 22
getPower: function() {
return powerScore
}
powerUp: function() {
powerScore = powerScore + 20
}
setPower: function(score) {
powerScore = score
}
favoriteFood: function() {
if(powerScore > 50) {
return 'chz'
}
else {
return 'mousetrap chz'
}
}
}
//debug ending here
}
Insert cell
Insert cell
Insert cell
Insert cell
function superCat() {
var superCat =
{
//write code here
}
return superCat;
}
Insert cell
Insert cell
Insert cell
superDoggo = function ()
{
var superDog =
{
//Write Code here
}
return superDog
}
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