"<p>John F. Kennedy</br>"
;
var
date
=
'June 26, 1963</p>'
;
document
.write(speaker);
document
.write(date);

Working with Strings
(cont’ d.)
String operators
–
Concatenation operator (+): combines two strings
var
destination
=
"Honolulu"
;
var
location
=
"Hawaii"
;
destination
=
destination
+
" is in "
+
location;
Compound assignment operator (+=): combines
two strings
var
destination
=
"Honolulu"
;
destination
+=
" is in Hawaii"
;
Plus sign
–
Concatenation operator and addition operator
JavaScript, Sixth Edition
31

Working with Strings
(cont’ d.)
Escape characters and sequences
–
Escape character
•
Tells the compiler or interpreter that the character that follows
has a special purpose
•
In JavaScript, escape character is backslash (\)
–
Escape sequence
•
Escape character combined with other characters
•
Most escape sequences carry out special functions
JavaScript, Sixth Edition
32

JavaScript, Sixth Edition
33
Table 2-4
JavaScript escape sequences
Working with Strings (cont’d.)

Using Operators to Build
Expressions
JavaScript, Sixth Edition
34
Table 2-5
JavaScript operator types
(continues)

JavaScript, Sixth Edition
35
Table 2-5
JavaScript operator types (cont'd.)
Using Operators to Build Expressions
(cont’d.)

Using Operators to Build
Expressions (cont’
d.)
Binary operator
–
Requires an operand before and after the operator
Unary operator
–
Requires a single operand either before or after the
operator
JavaScript, Sixth Edition
36

Arithmetic Operators
Perform mathematical calculations
–
Addition, subtraction, multiplication, division
–
Returns the modulus of a calculation
Arithmetic binary operators
JavaScript, Sixth Edition
37
Table 2-6
Arithmetic binary operators

Arithmetic Operators
(cont’ d.)
Arithmetic binary operators (cont’d.)
–
Value of operation on right side of the assignment
operator assigned to variable on the left side
–
Example:
arithmeticValue = x + y
;
•
Result assigned to the
arithmeticValue
variable
–
Division operator (/)
•
Standard mathematical division operation
–
Modulus operator (%)
•
Returns the remainder resulting from the division of two
integers
JavaScript, Sixth Edition
38

JavaScript, Sixth Edition
39
Figure 2-13
Division and modulus expressions
Arithmetic Operators (cont’d.)
var
divisionResult
=
15
/
6
;
var
modulusResult
=
15
%
6
;
document
.write(
"<p>15 divided by 6 is "
↵
+
divisionResult
+
".</p>"
);
// prints '2.5'
document
.write(
"<p>The whole number 6 goes into 15 twice,
↵
with a remainder of "
+
modulusResult
+
".</p>"
);↵
// prints '3'

Arithmetic Operators
(cont’ d.)
Arithmetic binary operators (cont’d.)
–
Assignment statement
•
Can include combination of variables and literal values on
the right side
•
Cannot include a literal value as the left operand
–
JavaScript interpreter
•
Attempts to convert the string values to numbers
•
Does not convert strings to numbers when using the addition
operator
JavaScript, Sixth Edition
40

Arithmetic Operators
(cont’ d.)
Prefix operator
–
Placed before a variable
Postfix operator
–
Placed after a variable
JavaScript, Sixth Edition
41
Table 2-7
Arithmetic unary operators

Arithmetic Operators
(cont’ d.)
Arithmetic unary operators
–
Performed on a single variable using unary operators
–

#### You've reached the end of your free preview.

Want to read all 61 pages?

- Fall '19
- Sixth Edition, Use functions