Assignment operators Comparison operators Arithmetic operators Bitwise operators Logical operators String operators Conditional (ternary) operator Comma operator Unary operators Relational operator
JavaScript Arithmetic Operators
Operator Description + Addition - Subtraction * Multiplication / Division % Modulus ++ Increment -- Decrement
JavaScript Assignment Operators
Assignment operators assign values to JavaScript variables. Operator Example = 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
JavaScript String Operators
The + operator can also be used to add (concatenate) strings. Adding Strings and Numbers Adding two numbers, will return the sum, but
adding a number and a string will return a string
: x = 5 + 5; y = "5" + 5; z = "Hello" + 5; The result of x, y, and z will be: 10 55 Hello5
JavaScript Comparison and Logical Operators
Operator Description == equal to === equal value and equal type != not equal !== not equal value or not equal type > greater than < less than >= greater than or equal to <= less than or equal to ? ternary operator
JavaScript Type Operators
Operator Description typeof Returns the type of a variable instanceof Returns true if an object is an instance of an object type
Javascript Comparison Operators
!= Is not equal to > Greater Than < Less Than >= Greater Than or equal to <= Less Than or equal to === Is exactly like and is of the same variable type as
Binary Logical Operators
Binary logical operators in JavaScript are short-circuiting. That is, if the first operand suffices for determining the result, the second operand is not evaluated. For example, in the following expressions, the function foo() is never called: false && foo() true || foo() And (&&) If the first operand is falsy, return it. Otherwise, return the second operand. Or (||) If the first operand is truthy, return it. Otherwise, return the second operand. Equality Operators JavaScript has two kinds of equality: Normal, or lenient, (in)equality: == and != Strict (in)equality: === and !== Numbers All numbers in JavaScript are floating-point
Logical operators
Operators you will want to use with your IF Statements are the logical ones. The logical operators give you more options for your IF statements. && Two ampersands mean AND || Two pipe characters mean OR ! One exclamation mark/point means NOT There are also some operations that can be applied to Boolean values themselves. JavaScript supports three logical operators: and, or, and not. The && operator represents logical and. It is a binary operator, and its result is true only if both the values given to it are true. console.log(true && false) // false console.log(true && true) // true The || operator denotes logical or. It produces true if either of the values given to it is true. console.log(false || true) // true console.log(false || false) // false Not is written as an exclamation mark (!). It is a unary operator that flips the value given to it-!true produces false and !false gives true.
The Ternary Operators
If you want a quick IF statement then you can use something called a ternary expression. This uses a question mark ( ? ) and a colon ( : ). The syntax is this: var result = condition_to_test ? "TRUE" : "FALSE"; Here's a coding example: var over_eighteen = true; var result = over_eighteen ? "Truth" : "False"; document.write(result);
up