4. Numbers
Good for... Not good for...
● A person’s age
● Day of the month
● Time
● Score in a game
● A person’s name
● Day name (Friday, etc.)
● Mailing address
● Chat message
5. Booleans
A binary value, having two possible values
called “true” and “false”
Bool·e·an
ˈbo͞olēən/
17. Functions
Group code into a reusable chunk.
function add(number1, number2) {
return number1 + number2;
}
function name
18. Functions
Group code into a reusable chunk.
function add(number1, number2) {
return number1 + number2;
}
argument argument
19. Functions
Group code into a reusable chunk.
function add(number1, number2) {
return number1 + number2;
}
function body
20. Functions
Group code into a reusable chunk.
function add(number1, number2) {
return number1 + number2;
} keyword
21. Functions
Group code into a reusable chunk.
function add(number1, number2) {
return number1 + number2;
} value to return
22. Functions
Group code into a reusable chunk.
function add(number1, number2) {
return number1 + number2;
}
keyword
function name
argument argument
keyword value to return
function body
31. Built-in Objects
Math.random(); // evaluates to a random number,
// between 0 and 1
console.log('Hello World'); // prints string to
// developer console
37. Strings
'Seth' - 'McLaughlin'; // evaluates to NaN
'Seth' / 'McLaughlin'; // evaluates to NaN
'Seth' * 'McLaughlin'; // evaluates to NaN
-, /, * operators do not apply to string values.
NaN means “Not A Number” (invalid value)
38. Strings
'Seth'.length; // evaluates to the number 4
'Seth'[1]; // evaluates to the string 'e'
'Seth'.indexOf('e'); // evaluates to the number 1
'Seth'.toUpperCase(); // evaluates to the string 'SETH'
'Seth'.toLowerCase(); // evaluates to the string 'seth'
Some of the built-in properties.
49. Arrays
Get an item
Richard Tom Susie
friends[2]; // evaluates to 'Tom'
friends[0]; // evaluates to 'Sara'
Sara
50. null and undefined
Special values to indicate a lack of value
var foo;
foo; // evaluates to undefined
var bar = null;
bar; // evaluates to null
51. null and undefined
function myFunction() {
var age = 34 + 10;
}
myFunction(); // evaluates to undefined since the
// function does not return a value
56. Write a function to multiply two numbers together,
and return the result.
57. Create an array to hold a list of state names. How can
you get the number of states in your list?
58. Create an object to represent a person. This object
should have two properties:
● name - a string
● sayHello - a function
When the function sayHello is invoked, the person’s
name should be printed to the browser’s console.