Published
Edited
Jan 29, 2020
Insert cell
Insert cell
3 // I'm a comment. #ComputerCantTouchThis
Insert cell
3 + 3 //addition
Insert cell
4 - 3 //subtraction
Insert cell
2 * 3.2 //multiplication
Insert cell
1 / 5 //division
Insert cell
10 % 3 //modulo
Insert cell
10 ** 3 //exponentiation
Insert cell
Insert cell
Insert cell
typeof 123
Insert cell
typeof 0.1
Insert cell
typeof "this is a string" // denoted by either "string value goes in here",
//'string value in here', or `string value in here`
Insert cell
typeof 'this is also a string'
Insert cell
typeof ""
Insert cell
typeof true // either true of false
Insert cell
typeof false
Insert cell
typeof undefined // the only possible value of an undefined type is undefined
Insert cell
// `typeof` doesn't work with `null` values for backwards compatability reasons.
typeof null
// when checking if something's explicitly `null`, make sure to use null === null
Insert cell
Insert cell
'bob' + 'mary'
Insert cell
'Luke, ' + 'I ' + 'am ' + 'your ' + 'father.'
Insert cell
Insert cell
true && true // the AND (&&) operator checks if both values are true
Insert cell
//if either one or both ANDed values are false,
true && false
//the operation returns false
Insert cell
true || true // the OR (||) operator checks if either value is true
Insert cell
//if one value is false, the result is still true
true || false
Insert cell
!true //The NOT (!) operator switches the boolean value
Insert cell
//Order of operations still applies in boolean algebra
!true && false || false || false
Insert cell
!(true && false) || false || false
Insert cell
Insert cell
{
var name = 'bob'
return name //this line is to make Observable happy
}
Insert cell
Insert cell
Insert cell
Insert cell
{
var num = 1
num = 2
return num
}
Insert cell
Insert cell
{
var one = 1
var two = 2
var three = one + two
return three
}
Insert cell
{
var firstName = 'Bob'
var lastName = 'Marley'
var fullName = firstName + ' ' + lastName
return fullName
}
Insert cell
{
var allMenAreMortal = true
var iAmAMan = true
return allMenAreMortal && iAmAMan
}
Insert cell
Insert cell
Insert cell
function converter (fahrenheit)
{
var Celsius = 0
Celsius = (fahrenheit-32)/(9/5)
return Celsius
}
Insert cell
Insert cell
Insert cell
function varWars1() {
var smartiesBot = true;
var sourBot = false;
var otherSourBot = sourBot;
return (smartiesBot || sourBot) || otherSourBot
}
Insert cell
Insert cell
function varWars2() {
var smartiesBot = true;
var sourBot = true;
var otherSourBot = false;
return (smartiesBot || sourBot || otherSourBot)
}
Insert cell
Insert cell
function varWarsArmageddon() {
var smartyKing = true;
var sourKidKing = false;
var smartiesBot = sourKidKing;// false
var thatOneSourBot = smartyKing;// true
return (smartiesBot || smartyKing) || (!sourKidKing && !sourKidKing) && thatOneSourBot && thatOneSourBot || (!smartiesBot && smartiesBot || !sourKidKing)
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more