Skip to Main Content
Learning PHP, MySQL, and JavaScript
book

Learning PHP, MySQL, and JavaScript

by Robin Nixon
July 2009
Beginner content levelBeginner
526 pages
14h 24m
English
O'Reilly Media, Inc.
Content preview from Learning PHP, MySQL, and JavaScript

Operators

JavaScript offers a lot of powerful operators that range from arithmetic, string, and logical operators to assignment, comparison, and more (see Table 15-1).

Table 15-1. JavaScript operator types

Operator

Description

Example

Arithmetic

Basic mathematics

a + b

Array

Array manipulation

a + b

Assignment

Assign values

a = b + 23

Bitwise

Manipulate bits within bytes

12 ^ 9

Comparison

Compare two values

a < b

Increment/Decrement

Add or subtract one

a++

Logical

Boolean

a && b

String

Concatenation

a + 'string'

Each operator takes a different number of operands:

  • Unary operators, such as incrementing (a++) or negation (-a) take a single operand.

  • Binary operators, which represent the bulk of JavaScript operators, including addition, subtraction, multiplication, and division.

  • One ternary operator, which takes the form ? x : y. It’s a terse single-line if statement that chooses between two expressions depending on a third one.

Operator Precedence

As with PHP, JavaScript utilizes operator precedence, in which some operators in an expression are considered more important than others and are therefore evaluated first. Table 15-2 lists JavaScript’s operators and their precedences.

Table 15-2. The precedence of JavaScript operators (high to low)

Operator(s)

Type(s)

() [] .

Parentheses, call, and member

++ --

Increment/decrement

+ - ~ !

Unary, bitwise, and logical

* / %

Arithmetic

+ -

Arithmetic and string

<< >> >>>

Bitwise

&

Bitwise

|

Bitwise

^

Bitwise

< > <= >=

Comparison

== != === !==

Comparison

&&

Logical

||

Logical

? :

Ternary

= += -= *= /= %= <<= ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Web Database Applications with PHP and MySQL, 2nd Edition

Web Database Applications with PHP and MySQL, 2nd Edition

Hugh E. Williams, David Lane
Learning PHP

Learning PHP

David Sklar

Publisher Resources

ISBN: 9780596803605Supplemental ContentErrata Page