Chapter 14 Answers

  1. The most noticeable difference between Boolean values in PHP and JavaScript is that PHP recognizes the keywords TRUE, true, FALSE, and false, whereas only true and false are supported in JavaScript. Additionally, in PHP, TRUE has a value of 1 and FALSE is NULL; in JavaScript they are represented by true and false, which can be returned as string values.

  2. The difference between unary, binary, and ternary operators is the number of operands each requires (one, two, and three, respectively).

  3. The best way to force your own operator precedence is to surround the parts of an expression to be evaluated first with parentheses.

  4. You use the identity operator when you wish to bypass JavaScript’s automatic operand type changing.

  5. The simplest forms of expressions are literals (such as numbers and strings) and variables, which simply evaluate to themselves.

  6. The three conditional statement types are if, switch, and the ? operator.

  7. Most conditional expressions in if and while statements are literal or Boolean and therefore trigger execution when they evaluate to TRUE. Numeric expressions trigger execution when they evaluate to a nonzero value. String expressions trigger execution when they evaluate to a nonempty string. A NULL value is evaluated as false and therefore does not trigger execution.

  8. Loops using for statements are more powerful than while loops because they support two additional parameters to control loop handling.

  9. The with statement takes an object as its parameter. Using ...

Get Learning PHP, MySQL, JavaScript, and CSS, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.