oneTwoThreeArray=[1,2,3,4,5]//this is how we declare an array
oneTwoThreeArray[0]
oneTwoThreeArray[oneTwoThreeArray.length-1]
emptyArray=[]//this is how we declare an empty array
emptyArray.push(1)
concatArray=emptyArray.concat([4,5,6])
concatArray.pop()
concatArray
myDog={
// This is how we declare an object!
varmyDog={
name:"fluffy",
breed:"bulldog",
color:"brown"
}
returnmyDog;
}
// To retrieve values to use them later
myDog.breed
{
vardoSomething=function(){
return"I'm doing awesome"
}
vardoSomethingTwo=doSomething
// These are equal!
returndoSomething===doSomethingTwo
}
myDog2={
varmyDog2={
name:"fluffy",
breed:"bulldog",
color:"brown",
bark:function(){
return"WOOF"
}
}
// just for observable~
returnmyDog2
}
// run it like this
myDog2.bark()
myDog3={
varmyDog3={
sayName:function(){
return"Hai my name is "+this.name+". I'm a "+this.breed+"."
},
name:"fluffykins",
breed:"bulldog",
}
returnmyDog3
}
myDog3.sayName()
thisOutOfContext=function(){
// what could `this` be?
returnthis;
}
justBark={
vardoggo={
bark:function(){
returnthis.sound
},
sound:"wooooof"
}
varjustBark=doggo.bark;
returnjustBark
}
// `this` is no longer the doggo
justBark()
boundBark={
vardoggo={
bark:function(){
returnthis.sound
},
sound:"wooooof"
}
varboundBark=doggo.bark;
returnboundBark.bind(doggo)
}
// `this` is doggo again
boundBark()
superCat=
{
varsupCat={
name:"fluffy",
purrStrength:9,
coatGlossLevel:5,
runThroughMud:function(){
this.coatGlossLevel-=1;
this.purrStrength-=1;
},
changeName:function(name){
this.name=name;
},
freeSpaDay:function(){
this.coatGlossLevel-=1;
this.purrStrength-=1;
}
}
returnsupCat;
//write code here
}
superDoggo=
{
varsuperDog={
name:"Charles",
speed:1000,
strength:1200,
eatDogFood:function(name){
this.speed*=2;
},
liftWeights:function(){
this.strength+=150;
},
drinkMilk:function(){
this.speed+=1000;
this.strength+=2000;
}
}
returnsuperDog;
}
theirArmy=["dog1","dog2","dog3","dog4"]
ourArmy=["superKitty"]
allAnimals=ourArmy.concat(theirArmy)
allAnimals.push("superDoggo")
allAnimals.indexOf("superKitty")
allAnimals.pop()
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.