feature post
Lists

JavaScript Operators

Operators
The operator itself is a keyword or symbol that does something to a value when used in an expression. For example, the arithmetic operator + adds two values together.
The symbol is used in an expression with either one or two values and performs a calculation on the values to generate a result. For example, here is an expression that uses the multiplication operator:
area = (width * height)
An expression is just like a mathematical expression. The values are known as operands. Operators that require only one operand (or value) are sometimes referred to as unary operators, while those that require two values are sometimes called binary operators.
Arithmetic Operators
Arithmetic operators perform arithmetic operations upon operands.

Operator Description
+ Addition
Subtraction
* Multiplication
/ Division
% Modulus (Remainder)
++ Increment
Decrement

Assignment Operators
The basic assignment operator is the equal sign, but do not take this to mean that it checks whether two values are equal.
Rather, it ’ s used to assign a value to the variable on the left of the equal sign.
The basic assignment operator can be combined with several other operators to allow you to assign a value to a variable and perform an operation in one step. For example, take a look at the following statement where there is an assignment operator and an arithmetic operator:
total = total – profit
This can be reduced to the following statement:
total -= profit

perator Example Same As
= x = y x = y
+= x += y x = x + y
-= x -= y x = x – y
*= x *= y x = x * y
/= x /= y x = x / y
%= x %= y x = x % y

Comparison Operators
Comparison operators compare two operands and then return either true or false based on whether the comparison is true or not.

Operator Description Comparing Returns
== equal to x == 8 false
=== equal value and equal type x === 5 true
x === “5” false
!= not equal x != 8 true
!== not equal value or not equal type x !== 5 false
x !== “5” true
x !== 8 true
> greater than x > 8 false
< less than x < 8 true
>= greater than or equal to x >= 8 false
<= less than or equal to x <= 8 true

Logical or Boolean Operators
Logical or Boolean operators return one of two values: true or false. They are particularly helpful when you want to evaluate more than one expression at a time.

Operator Description Example
&& and (x < 10 && y > 1) is true
|| or (x == 5 || y == 5) is false
! not !(x == y) is true

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.