Operators

MetaScript has assignment, comparison, arithmetic, bitwise, logical, string, and special operators. This chapter describes the operators and contains information about operator precedence.

The following table summarizes the MetaScript operators.

Operator category Operator Description
Arithmetic Operators + (Addition) Adds two numbers.
  ++ (Increment) Adds one to a variable representing a number (returning either the new or old value of the variable)
  - (Unary negation, subtraction) As a unary operator, negates the value of its argument. As a binary operator, subtracts two numbers.
  -- (Decrement) Subtracts one from a variable representing a number (returning either the new or old value of the variable)
  * (Multiplication) Multiplies two numbers.
  / (Division) Divides two numbers.
  % (Modulus) Computes the integer remainder of dividing two numbers.
String Operators + (String addition) Concatenates two strings.
  += Concatenates 2 strings and assigns the result to the first operand.
Logical Operators && (Logical AND) Returns the first operand if it can be converted to false; otherwise, returns the second operand. Thus, when used with Boolean values, && returns true if both operands are true; otherwise, returns false.
  || (Logical OR) Returns the first operand if it can be converted to true; otherwise, returns the second operand. Thus, when used with Boolean values, || returns true if either operand is true; if both are false, returns false.
  ! (Logical NOT) Returns false if its single operand can be converted to true; otherwise, returns true.
Bitwise Operators & (Bitwise AND) Returns a one in each bit position if bits of both operands are ones.
  ^ (Bitwise XOR) Returns a one in a bit position if bits of one but not both operands are one.
  | (Bitwise OR) Returns a one in a bit if bits of either operand is one.
  ~ (Bitwise NOT) Flips the bits of its operand.
  << (Left shift) Shifts its first operand in binary representation the number of bits to the left specified in the second operand, shifting in zeros from the right.
  >> (Sign-propagating right shift) Shifts the first operand in binary representation the number of bits to the right specified in the second operand, discarding bits shifted off.
  >>> (Zero-fill right shift) Shifts the first operand in binary representation the number of bits to the right specified in the second operand, discarding bits shifted off, and shifting in zeros from the left.
Assignment Operators = Assigns the value of the second operand to the first operand.
  += Adds two numbers and assigns the result to the first.
  -= Subtracts two numbers and assigns the result to the first.
  *= Multiplies two numbers and assigns the result to the first.
  /= Divides two numbers and assigns the result to the first.
  %= Computes the modulus of two numbers and assigns the result to the first.
  &= Performs a bitwise AND and assigns the result to the first operand.
  ^= Performs a bitwise XOR and assigns the result to the first operand.
  |= Performs a bitwise OR and assigns the result to the first operand.
  <<= Performs a left shift and assigns the result to the first operand.
  >>= Performs a sign-propagating right shift and assigns the result to the first operand.
  >>>= Performs a zero-fill right shift and assigns the result to the first operand.
Comparison Operators == Returns true if the operands are equal.
  != Returns true if the operands are not equal.
  === Returns true if the operands are equal and of the same type.
  !== Returns true if the operands are not equal and/or not of the same type.
  > Returns true if the left operand is greater than the right operand.
  >= Returns true if the left operand is greater than or equal to the right operand.
  < Returns true if the left operand is less than the right operand.
  <= Returns true if the left operand is less than or equal to the right operand.
Special Operators ?: Performs a simple "if...then...else"
  , Evaluates two expressions and returns the result of the second expression.
  delete Deletes an object, an object's property, or an element at a specified index in an array.
  in Returns true if the specified property is in the specified object.
  instanceof Returns true if the specified object is of the specified object type.
  new Creates an instance of a user-defined object type or of one of the built-in object types.
  this Keyword that you can use to refer to the current object.
  typeof Returns a string indicating the type of the unevaluated operand.
  void Specifies an expression to be evaluated without returning a value.
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.