 # Expressions

• Arithmetic: evaluates to a number, for example 3.14159
• String: evaluates to a character string, for example, "Fred" or "234"
• Logical: evaluates to true or false

```myArray=new Array()if (!myArray["notThere"])   myFunction()
```

## Conditional expressions

```(condition) ? val1 : val2
```

```status = (age >= 18) ? "adult" : "minor"
```

# Operators

```operand1 operator operand2
```

```operator operand
```

```operand operator
```

## Assignment operators

Implemented in Navigator 2.0

Shorthand operator
Meaning
x += y
x = x + y
x -= y
x = x - y
x *= y
x = x * y
x /= y
x = x / y
x %= y
x = x % y
x <<= y
x = x << y
x >>= y
x = x >> y
x >>>= y
x = x >>> y
x &= y
x = x & y
x ^= y
x = x ^ y
x |= y
x = x | y

## Comparison operators

Implemented in Navigator 2.0

Operator Description Example
Equal (= =)
Returns true if the operands are equal.
x == y returns true if x equals y.
Not equal (!=)
Returns true if the operands are not equal.
x != y returns true if x is not equal to y.
Greater than (>)
Returns true if left operand is greater than right operand.
x > y returns true if x is greater than y.
Greater than or equal (>=)
Returns true if left operand is greater than or equal to right operand.
x >= y returns true if x is greater than or equal to y.
Less than (<)
Returns true if left operand is less than right operand.
x < y returns true if x is less than y.
Less than or equal (<=)
Returns true if left operand is less than or equal to right operand.
x <= y returns true if x is less than or equal to y.

## Arithmetic operators

### Modulus (%)

Implemented in Navigator 2.0

```var1 % var2
```

### Increment (++)

Implemented in Navigator 2.0

### Decrement (--)

Implemented in Navigator 2.0

### Unary negation (-)

Implemented in Navigator 2.0

## Bitwise operators

Operator Usage Description
Bitwise AND
a & b
Returns a one in each bit position if bits of both operands are ones.
Bitwise OR
a | b
Returns a one in a bit if bits of either operand is one.
Bitwise XOR
a ^ b
Returns a one in a bit position if bits of one but not both operands are one.
Bitwise NOT
~ a
Flips the bits of its operand.
Left shift
a << b
Shifts a in binary representation b bits to left, shifting in zeros from the right.
Sign-propagating right shift
a >> b
Shifts a in binary representation b bits to right, discarding bits shifted off.
Zero-fill right shift
a >>> b
Shifts a in binary representation b bits to the right, discarding bits shifted off, and shifting in zeros from the left.

### Bitwise logical operators

Implemented in Navigator 2.0

• The operands are converted to thirty-two-bit integers and expressed by a series of bits (zeros and ones).
• Each bit in the first operand is paired with the corresponding bit in the second operand: first bit to first bit, second bit to second bit, and so on.
• The operator is applied to each pair of bits, and the result is constructed bitwise.

• 15 & 9 yields 9 (1111 & 1001 = 1001)
• 15 | 9 yields 15 (1111 | 1001 = 1111)
• 15 ^ 9 yields 6 (1111 ^ 1001 = 0110)

### Bitwise shift operators

Implemented in Navigator 2.0

## Logical operators

Implemented in Navigator 2.0

Operator Usage Description
and (&&)
expr1 && expr2
Returns true if both logical expressions expr1 and expr2 are true. Otherwise, returns false.
or (||)
expr1 || expr2
Returns true if either logical expression expr1 or expr2 is true. If both are false, returns false.
not (!)
!expr
If expr is true, returns false; if expr is false, returns true.

### Short-circuit evaluation

• false && anything is short-circuit evaluated to false.
• true || anything is short-circuit evaluated to true.

## String operators

Implemented in Navigator 2.0

## Special operators

### new

Implemented in Navigator 2.0

```objectName = new objectType ( param1 [,param2] ...[,paramN] )
```

### typeof

Implemented in Navigator 3.0

```1. typeof operand2. typeof (operand)
```

```var myFun = new Function("5+2")var shape="round"var size=1var today=new Date()
```

```typeof myFun is objecttypeof shape is stringtypeof size is numbertypeof today is objecttypeof dontExist is undefined
```

```typeof true is booleantypeof null is object
```

```typeof 62 is numbertypeof 'Hello world' is string
```

```typeof document.lastModified is stringtypeof window.length is numbertypeof Math.LN2 is number
```

```typeof blur is functiontypeof eval is functiontypeof parseInt is functiontypeof shape.split is function
```

```typeof Date is functiontypeof Function is functiontypeof Math is functiontypeof Option is functiontypeof String is function
```

### void

Implemented in Navigator 3.0

```1. javascript:void (expression)2. javascript:void expression
```

```<A HREF="javascript:void(0)">Click here to do nothing</A>
```

```<A HREF="javascript:void(document.form.submit())">Click here to submit</A>
```

## Operator precedence

Operator Examples
assignment
``` = += -= *= /= %= <<= >>= >>>= &= ^= |= ```
conditional
` ?: `
logical-or
` || `
logical-and
` && `
bitwise-or
` | `
bitwise-xor
` ^ `
bitwise-and
` & `
equality
` == != `
relational
` < <= > >= `
bitwise shift
``` << >> >>> ```
` + - `
multiply/divide
` * / % `
negation/increment
` ! ~ - ++ -- typeof void `
call, member
` () [] . `

 file: /Techref/language/java/script/expr.htm, 31KB, , updated: 2009/2/2 14:27, local time: 2019/7/22 05:44, TOP NEW HELP FIND:  3.81.73.233:LOG IN

 ©2019 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?Please DO link to this page! Digg it! / MAKE! /  Expressions and operators

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.

Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
 Did you find what you needed? "No. I'm looking for: " "No. Take me to the search page." "No. Take me to the top so I can drill down by catagory" "No. I'm willing to pay for help, please refer me to a qualified consultant" "No. But I'm interested. me at when this page is expanded."

.