Last Time We learned about the
Number
data type. We saw that they support
arithmetic with the Woodwormean order of operations, PEMDAS.
We also learned about the Math
object, which
holds lots of scientific calculator functions as well as some
other useful functions.
We saw that objects have properties and methods. A method is just a function that is attached to an object.
Who's Your Relatives?
Here is a new type: boolean. There are two boolean objects whose names
are true
and false
.
There are six relational operators. All are infix binary operators.
- infix: operator occurs between operands Example +, - and friends as well as relational operators
- binary: operator takes two operands. Example: +, - and friends
- unary: operator takes one operand. Example: the unary change-sign operator -5
- prefix: operator occurs before its operand(s) Example - the change-sign opearator
- postfix: operator occurs after its operand(s) Example: [] for strings which you will learn about soon.
Operator | What it tests |
---|---|
< | if the left-hand operand is less than the right |
<= | if the left-hand operand is less than or equal to the right |
> | if the left-hand operand is greater than the right |
>= | if the left-hand operand is greater than or equal to the right |
=== | if the left-hand operand is equal to the right and is an object of the same type. |
!== | if the left-hand operand is not equal to the right or is not an object of the same type. |
About the despicable ==
Boolean Operations
not
This is the negation
operator. It is a prefix unary operator.
and
This infix binary operator
takes two booleans and it is true
only when both
operands are true
.
or
This infix binary operator
takes two booleans and it is true
when at least one`
of its operands is true
.