Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

5.2. Operator Overview

If you are a C, C++, or Java programmer, most of the JavaScript operators should already be familiar to you. Table 5-1 summarizes the operators; you can use this table as a reference. Note that most operators are represented by punctuation characters such as + and =. Some, however, are represented by keywords such as delete and instanceof. Keyword operators are regular operators, just like those expressed with punctuation; they are simply expressed using a more readable and less succinct syntax.

Table 5-1. JavaScript operators
PAOperatorOperand type(s)Operation performed
15L . object, identifierProperty access
L [] array, integerArray index
L ( ) function, argumentsFunction call
R new constructor callCreate new object
14R ++ lvaluePre- or post-increment (unary)
R -- lvaluePre- or post-decrement (unary)
R - numberUnary minus (negation)
R + numberUnary plus (no-op)
R ~ integerBitwise complement (unary)
R ! booleanLogical complement (unary)
R delete lvalueUndefine a property (unary)
R typeof anyReturn datatype (unary)
R void anyReturn undefined value (unary)
13L *, /, % numbersMultiplication, division, remainder
12L +, - numbersAddition, subtraction
L + stringsString concatenation
11L << integersLeft shift
L >> integersRight shift with sign extension
L >>> integersRight shift with zero extension
10L <, <= numbers or stringsLess than, less than or equal
L >, >= numbers or stringsGreater than, greater than or equal
L instanceof object, constructorCheck object type
L in string, objectCheck whether property exists
9L == anyTest for equality
L != anyTest for inequality
L === anyTest for identity
L !== anyTest for nonidentity
8L & integersBitwise AND
7L ^ integersBitwise XOR
6L | integersBitwise OR
5L && booleansLogical AND
4L || booleansLogical OR
3R ?: boolean, any, anyConditional operator (three operands)
2R = lvalue, anyAssignment
R *=, /=, %=, +=, -=, <<=, >>=, >>>=, &=, ^=, |= lvalue, anyAssignment with operation
1L , anyMultiple evaluation



  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint