Published
Edited
Jan 28, 2019
5 forks
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" 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 undefined value 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
typeof Symbol.iterator
Insert cell
Insert cell
6 + 3 // addition
Insert cell
6 - 3 // subtraction
Insert cell
6 * 3 // multiplication
Insert cell
6 / 3 // division
Insert cell
Insert cell
10 % 3 // If you divide 10 by 3, you get 3 and a remainder of 1
Insert cell
Insert cell
3 > 2 // 3 is greater than 2
Insert cell
3 < 2 // 3 is not less than 2 so this "outputs" or "returns" false
Insert cell
3 >= 3 // 3 is greater than or equal to 3
Insert cell
3 <= 4 // 3 is less than or equal to 4
Insert cell
Insert cell
3 == 3 // 3 is equal to 3
Insert cell
3 === 3 // 3 is equal to 3
Insert cell
3 == 2 // 3 isn't equal to 2 so this outputs or "returns" false
Insert cell
3 === 2 // 3 isn't equal to 2 so this outputs or "returns" false
Insert cell
3 != 2 // 3 isn't equal to 2
Insert cell
3 != 3 // 3 is equal to 3 so this outputs or "returns" false
Insert cell
3 !== 2 // 3 isn't equal to 2
Insert cell
Insert cell
Insert cell
"Hello" + " " + "World"
Insert cell
"444" + "-" + "444" + "-" + "4444"
Insert cell
Insert cell
true && true // the and operator outputs or "returns" true if both booleans given are true
Insert cell
true && false
Insert cell
false && false
Insert cell
true || false // the "or" operator returns true if at least one of the booleans given is true
Insert cell
true || true
Insert cell
false || false
Insert cell
!false // the negation operator "!" will flip the boolean value that comes after it.
// the opposite of false is true
Insert cell
!true // the opposite of true is false
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
num1 + num2
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
firstName + " " + lastName
Insert cell
Insert cell
Insert cell
Insert cell
true + true
Insert cell
+null == 0
Insert cell
"3" + 1
Insert cell
"3" - - 1
Insert cell
1 + + "3"
Insert cell
false == ""
Insert cell
!""
Insert cell
Insert cell
Insert cell
!!0 // 0 is falsy
Insert cell
!!null // null is falsy
Insert cell
!!undefined // undefined is falsey
Insert cell
!!"" // an empty string is falsy
Insert cell
!!123 // numbers other than 0 are truthy
Insert cell
!!"this is a string" // non-empty strings are truthy
Insert cell
Insert cell
Insert cell
"" == false
Insert cell
0 == false
Insert cell
"foobar" == true
Insert cell
"1" == 1
Insert cell
0 == "0"
Insert cell
undefined == null
Insert cell
Insert cell
"" === false
Insert cell
0 === false
Insert cell
"foobar" === true
Insert cell
"1" === 1
Insert cell
0 === "0"
Insert cell
undefined === null
Insert cell
Insert cell
Insert cell
{
// Like so:
return "this is my answer"
// This allows the value to be printed in this notebook.
// This isn't a JavaScript feature but rather a quirk of this website.
}
Insert cell
Insert cell
{
// Your Code Here
}
Insert cell
Insert cell
{
// Your Code Here
}
Insert cell
Insert cell
{
// Your Code Here
}
Insert cell
Insert cell
{
// Your Code Here
}
Insert cell
Insert cell
{
// Your code here
}
Insert cell
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