Java Reference
In-Depth Information
I will defer the discussion of the Object type until I finish explaining the basic
constructs in Nashorn such as operators, statements, loops, and so on.
Operators
Nashorn supports many operators. Most of them are the same as Java operators. I will
list all operators in this section and discuss a few of them here. I will discuss others in
subsequent sections when appropriate. Table 4-5 lists operators in Nashorn.
Table 4-5. The List of Operators in Nashorn
Operator
Name
Syntax
Description
++
++i
i++
Increment
Increments the operand by 1.
--
--i
i--
Decrement
Decrements the operand by 1.
delete
delete prop
Deletes the specified property from an
object.
void
void expr
Discards the return value of the specified
expression.
typeof
typeof expr
Returns a String describing the type of
the specified expression.
+
+op
Unary Plus
Converts the operand to the Number
type.
-
-op
Unary
Negation
Converts the operand to the Number
type and then negates the converted
value.
~
~op
Bitwise NOT
Uses the operand as a 32-bit signed
integer, flips its bits, and returns the
result as a 32-bit signed integer.
!
!expr
Returns true if expr evaluates to false .
Returns false if expr evaluates to true .
Logical NOT
+
op1 + op2
Numeric
addition/
string
concatenation
Performs a string concatenation if one
of the operands is a string or they can be
converted to string. Otherwise, performs
numeric addition.
-
op1 - op2
Subtraction
Performs numeric subtraction on the two
operands, converting them to numbers if
they are not numbers.
( continued )
 
Search WWH ::




Custom Search