+ should be used in mathematical context as an arithmetic operator.

The summary:

Variable Type1 | Variable Type2 | Operator + |
---|---|---|

numeric | numeric | Will add them |

String | String | Will Concatenate them |

numeric | String | Will try to add them if the String is not in proper format we will get subtype mismatch error |

#### Logical operators:

Logical operators can be used to test or perform logical operations or expressions. We use them mostly in control statements.

Sign | Name | Syntax | Description |
---|---|---|---|

Not | Logical Not | if (Not variable1) | Returns the logical negation of an expression,except Null.Null will return Null only. It returns false if the expression is true and returns true if the expression is false. |

AND | Logical AND | expression1 AND expression2 | It checks if both expressions are true.Expressions need to be evaluated as boolean. It returns true if both the expressions are true,false otherwise. |

OR | Logical OR | expression1 OR expression2 | It checks if one of the expressions is true.Expressions need to be evaluated as boolean. It returns true if one of the expressions are true,false otherwise |

XOR | Logical XOR | expression1 XOR expression2 | It checks if one and only one expression is true.It returns true when one of the expressions is true, false otherwise.Incase of Null,Null will be returned,if one of the expression is evaluated as Null. |

Eqv | Logical Equivalence | expression1 Eqv expression2 | A equivalence operation to check if both expressions or variables evaluates same value. In case if one of the expression is evaluated as Null,this check will return Null. |

Imp | Logical Implication | expression1 Imp expression2 | Logical implication operator follows the following table as truth table. |

The truth table for logical implication:

Expression1 | Expression2 | Output |
---|---|---|

true | true | true |

false | true | true |

false | false | true |

false | Null | true |

Null | true | true |

true | false | false |

true | Null | Null |

Null | false | Null |

Null | Null | Null |

#### Bitwise Operators:

Bitwise operators are comparison operators. They check bit by bit information while comparing.

Sign | Name | Syntax | Description |
---|---|---|---|

Not | Bitwise Not | if (Not variale1/Expression1) | Not is used to invert the bit value.It will return 1 if the bit is 0 and will return 0 if the bit value is 1. Expression-111 will output as 000(Not Expression) |

AND | Bitwise AND | expression1 AND expression2 | AND is used to check if both the bits are set to 1. It returns 1 if both the bits are 1.0 otherwise. Expression1=1000 Expression2=1010 Output=1000 |

OR | Bitwise OR | expression1 OR expression2 | OR is used to check if one bit or both the bits is either expression is set to 1 returns 1 if one of the bits is 1,0 therwise Expression1=1010 Expression2=0101 Output=1111 |

XOR | Bitwise XOR | expression1 XOR expression2 | XOR is used to check if one and only one bits is set to 1. Returns if only one of the bits is 1 , 0 otherwise.Expression1=1010 Expression2=0110 Output=1100 |

Eqv | Bitwise Equivalence | expression1 Eqv expression2 | Eqv is used to check if both bits are of same value. It returns 1 if both bits are same value returns 0 if both bits are different value.Expression1=1001 Expression2=1011 Output=1101 |

Imp | Bitwise Implication | expression1 Imp expression2 | Imp is used to perform implication of 2 bits. If follows the below truth table.
Expression1=1010 |

The truthtable of Bitwise Implication is given as:

Expression1 | Expression2 | Output |
---|---|---|

0 | 0 | 1 |

0 | 1 | 1 |

1 | 1 | 1 |

1 | 0 | 0 |

### Operator Precedence:

When several operations occur in an expression, each part is evaluated and resolved in a predetermined order called operator precedence.

We can use parentheses to override the order of precedence and force some parts of an expression to be evaluated before others.

Operations within parentheses are always performed before those outside. Within parentheses, however, standard operator precedence is maintained.

When expressions contain operators from more than one category, arithmetic operators are evaluated first, comparison operators are evaluated next, and logical operators are evaluated last.

Comparison operators all have equal precedence; that is, they are evaluated in the left-to-right order in which they appear.

Arithmetic and logical operators are evaluated in the following order of precedence.

### Precedence Table in VBScript

Operator | Precedence | Expressions |
---|---|---|

Arithmetic Operator | 1 | ^,-,*,/,Mod,+,- |

Concatenation Operator | 2 | &,+ |

Comparison Operator | 3 | =,<>,<,>,<=,>=,IS |

Bitwise Operator | 4 | NOT,AND,OR,XOR,Eqv,Imp |

Assignment Operator | 5 | = |

### Difference between ampersand(&) character and the underscore (_) character?

Ampersand (&) character is an operator to use concatenation of Strings. it is used to join two small strings together. On the other hand underscore (_) character is to continue a VBScript long statement across multiple lines.