Published byModified over 4 years ago
3 Statements End with semi-colon Cannot occupy multiple lines Assignment statement var = value; The “value” on the right can be any legal expression Function call document.write ("foo");
7 Data Type A characterization of a stored value Determines what kinds of values can be stored how the value is stored internally what operations can be applied Syntactic representation how the value is expressed in a program
9 Strings What values lists of characters any length including the zero-length “null” string “” What operations concatenation (+ operator) output to the Web page using document.write(…) returned by prompt() function Syntax double or single quotes
11 Integers What values whole numbers between -9223372036854775808 and 9223372036854775808 What operations standard mathematical operations (+, -, *, /) special math functions Syntax unquoted integers Note book doesn't use integers in examples
13 Float What values decimal values from ±1.0x10 308 to ± 1.0x10 -323 17 digits of precision (past decimal point) What operations standard mathematical operations special math functions Syntax unquoted decimal values scientific notation 1.2e3 = 1.2 x 10 3 = 1200
17 Another kind of value var foo; document.write (foo); What is the value of foo?
18 undefined value This is the value of a variable when it is created if you use a variable without defining it, you get an error You can declare a variable without giving it a value not an error variable has no value unexpected results
20 Syntax alert An expression is not a statement an expression may be part of a statement note: no semi-colon Example (a + b) / 2 expression size = a + b; statement
21 Evaluation An expression is evaluated when it is executed (run-time) Steps Each variable is replaced by its current value Operators are applied Until a single value remains
22 Example a = 5; b = 20; position = (a * 5) + (b / 10);
25 The "+" trap + means different things for different types "foo" + "bar" "foobar" "5" + "6" "56" 5 + 6 11 What about? "5" + 6 6 + "foo"
26 Operators + is an operator An operator takes two values (sometimes one) makes ("returns") a new value Some operators are two characters && Assignment is not an operation = is not an operator!
27 Functions Like an operator takes values does some operation returns a result But has a name instead of symbol can take any number of values can be user-defined
28 Predefined Functions You can define your own functions later in the class Many built-in prompt document.write
29 Function syntax prompt ( "Enter a number", "0") return value is a string containing the user input No parameters? Math.random () there's still a list, just an empty one function nameparameter #1 parameter #2 parameter list