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.
The difference between unary, binary, and ternary operators is the number of operands each requires (one, two, and three, respectively).
The best way to force your own operator precedence is to surround the parts of an expression to be evaluated first with parentheses.
You use the identity operator when you wish to bypass JavaScript’s automatic operand type changing.
The simplest forms of expressions are literals (such as numbers and strings) and variables, which simply evaluate to themselves.
The three conditional statement types are if
, switch
, and the ?
operator.
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.
Loops using for
statements
are more powerful than while
loops
because they support two additional parameters to control loop
handling.
The with
statement takes an
object as its parameter. Using it, you specify an object once; then,
for each statement within the with
block, that object is assumed.
To handle errors gracefully use the try
function, which will pass any error
encountered to a matching catch
function, where you can process the error or provide alternate code.
You can also attach code to the onerror
event.