Examples of expressions that can be converted to false are those that evaluate to null, 0, NaN, the empty string "" , or undefined. As logical expressions are evaluated left to right, they are tested for possible "short-circuit" evaluation using the following rules:. The rules of logic guarantee that these evaluations are always correct. Note that the anything part of the above expressions is not evaluated, so any side effects of doing so do not take effect.
This operator is primarily used inside a for loop, to allow multiple variables to be updated each time through the loop. The code prints the values of the diagonal elements in the array:. The delete operator deletes an object, an object's property, or an element at a specified index in an array.
The fourth form is legal only within a with statement, to delete a property from an object. You can use the delete operator to delete variables declared implicitly but not those declared with the var statement. If the delete operator succeeds, it sets the property or element to undefined. The delete operator returns true if the operation is possible; it returns false if the operation is not possible.
When you delete an array element, the array length is not affected. For example, if you delete a , a is still a and a is undefined. When the delete operator removes an array element, that element is no longer in the array.
In the following example, trees is removed with delete. However, trees is still addressable and returns undefined.
If you want an array element to exist but have an undefined value, use the undefined keyword instead of the delete operator. In the following example, trees is assigned the value undefined , but the array element still exists:. The typeof operator is used in either of the following ways:. The typeof operator returns a string indicating the type of the unevaluated operand. The parentheses are optional. For the keywords true and null , the typeof operator returns the following results:.
For property values, the typeof operator returns the type of value the property contains:. The void operator is used in either of the following ways:. The void operator specifies an expression to be evaluated without returning a value. The parentheses surrounding the expression are optional, but it is good style to use them. You can use the void operator to specify an expression as a hypertext link. The expression is evaluated but is not loaded in place of the current document. The following code creates a hypertext link that does nothing when the user clicks it.
The in operator returns true if the specified property is in the specified object. The instanceof operator returns true if the specified object is of the specified object type. Use instanceof when you need to confirm the type of an object at runtime. For example, when catching exceptions, you can branch to different exception-handling code depending on the type of exception thrown.
For example, the following code uses instanceof to determine whether theDay is a Date object. Because theDay is a Date object, the statements in the if statement execute.
The grouping operator controls the precedence of evaluation in expressions. For example, you can override multiplication and division first, then addition and subtraction to evaluate addition first. There are two versions of comprehensions:. Comprehensions exist in many programming languages and allow you to quickly assemble a new array based on an existing one, for example.
You can use the new operator to create an instance of a user-defined object type or of one of the built-in object types. Use new as follows:. The super keyword is used to call functions on an object's parent. The spread operator allows an expression to be expanded in places where multiple arguments for function calls or multiple elements for array literals are expected. Bitwise operators treat their operands as a sequence of 32 bits zeroes and ones , rather than as decimal, hexadecimal, or octal numbers.
Two's complement format means that a number's negative counterpart e. For example, the following encodes the integer The two's complement guarantees that the left-most bit is 0 when the number is positive and 1 when the number is negative.
Thus, it is called the sign bit. The number hexadecimal representation: The numbers and are the minimum and the maximum integers representable through a 32bit signed number. Performs the AND operation on each pair of bits.
The truth table for the AND operation is:. Bitwise ANDing any number x with 0 yields 0. Bitwise ANDing any number x with -1 yields x. Performs the OR operation on each pair of bits. The truth table for the OR operation is:. Bitwise ORing any number x with 0 yields x. Bitwise ORing any number x with -1 yields Performs the XOR operation on each pair of bits. The truth table for the XOR operation is:.
Bitwise XORing any number x with 0 yields x. Performs the NOT operator on each bit. NOT a yields the inverted value a. The truth table for the NOT operation is:. The bitwise shift operators take two operands: The direction of the shift operation is controlled by the operator used. Shift operators convert their operands to bit integers in big-endian order and return a result of the same type as the left operand.
The right operand should be less than 32, but if not only the low five bits will be used. This operator shifts the first operand the specified number of bits to the left. Excess bits shifted off to the left are discarded. Zero bits are shifted in from the right. This operator shifts the first operand the specified number of bits to the right. Excess bits shifted off to the right are discarded.
Copies of the leftmost bit are shifted in from the left. Since the new leftmost bit has the same value as the previous leftmost bit, the sign bit the leftmost bit does not change. Hence the name "sign-propagating". Zero bits are shifted in from the left.