Powerpoint

advertisement
JavaScript
VARIABLES AND DATA TYPES
OUTPUT WITHOUT
ALERT OR FORM
CONSOLE.LOG();
Holding information
example
Cubby Hole 3:
place it here
Cubby Hole 2:
add this value
A = B + C;
Cubby Hole 1:
take this value
Defining CUBBY HOLES
They
are called variables

Define them

Give them values

Take values from them
= means “takes the value of”
A takes the value of B+C
VALUES
What values can it take?

Any “expression”

What is an expression?


Variables

Constants

Operators

functions
Different for numbers and strings
Numbers

Regular math operators

Variables

Constants

Functions (random, floor)
Strings

Think of Scrabble tiles

Each tile is a

Letter

Number

Punctuation mark

Space (blank)
What is a String?
A
literal string must be inside
double quotes or single quotes
 “this
is a string” and this is not a string.
 Remember
to beware cut and paste
Concatenating (formally)

It means combining two or more things
into one thing

+ Anything can be concatenated
 “awe”
& “some” = “awesome”
 Whitespace
 “a”+“b”
 “a
only matters inside quotes
same as “a” = “b”
” + “b” NOT the same as “a” + “b”
Substring
A
substring is also a String
A
substring is a part of another string
 “cake”
 so
are “day”, “thd”, and “y cake”
 “they”
 Will
is a substring of “birthday cake”
is not, neither is “hello” or “dude”
come back to how to extract
substrings
Referencing characters
Each character has a position
H I
0
1
M O M
2
3
4
Note that it starts at 0, not 1
5
Download