Page 132 - CITS - Computer Software Application -TT
P. 132
COMPUTER SOFTWARE APPLICATION - CITS
Note
If you add a number and a string, the result will be a string!
JavaScript Logical Operators
Operator Description
&& logical and
|| logical or
! logical not
Note
Logical operators are fully described in the JS Comparisons chapter.
JavaScript Type Operators
Operator Description
Type of Returns the type of a variable
Instance of Returns true if an object is an instance of an
object type
Note
Type operators are fully described in the JS Type Conversion chapter.
JavaScript Bitwise Operators
Bit operators work on 32 bits numbers.
Any numeric operand in the operation is converted into a 32 bit number. The result is converted back to a
JavaScript number.
Operator Description Example Same as Result Decimal
& AND 5 & 1 0101 & 0001 1
0001
| OR 5 | 1 0101 | 0101 5
0001
~ NOT ~ 5 ~0101 1010 10
^ XOR 5 ^ 1 0101 ^ 0100 4
0001
<< left shift 5 << 1 0101 << 1 1010 10
>> right shift 5 >> 1 0101 >> 1 0010 2
>>> unsigned right 5 >>> 1 0101 >>> 0010 2
shift 1
The examples above uses 4 bits unsigned examples. But JavaScript uses 32-bit signed numbers.
Because of this, in JavaScript, ~ 5 will not return 10. It will return -6.
~00000000000000000000000000000101 will return 11111111111111111111111111111010
Bitwise operators are fully described in the JS Bitwise chapter.
JavaScript’s expression is a valid set of literals, variables, operators, and expressions that evaluate a single value
that is an expression. This single value can be a number, a string, or a logical value depending on the expression.
Example:
• Javascript
119
CITS : IT&ITES - Computer Software Application - Lesson 37 - 46