- They are tools to evaluate an expression consisting of a certain number of arguments
- +,-,*,/,% etc.
- And &&, or ||, not !
Answers
-
Operators define operations that can be taken on values.
-
The most common binary operators are:
- Addiction (+);
- Subtraction (-);
- Multiplication (*);
- Division (/);
- Modulo (%).
- Javascript supports three logical operators:
- && and --> console.log(true && false) = false;
- || or --> console.log(true || false) = true;
- ! not --> console.log(!true) = false.
- A symbol that effects values
- < > =
- && || !
1 Operators perform some sort of operation on either single or multiple operants that end in values.
-
Some binary operators include; +, -, / and %
-
Some logical operators include; ==, <=, >=, <, >, !, !=, ||, &&, === and !==
- Operators in JS are constructs which behave similarly to functions, but which differ in syntax and/or semantics from usual functions.
- +, -, /, and %
- Logical operators are usually also binary. I know: ==, <, >, <=, >=, &&, ===, !, and ||.
-
Operators are symbols that take actions on values.
-
Some binary operators I know are: > (is greater than), < (is less than), >= (greater than or equal to), <= (less than or equal to), == (equal to), and != (not equal to), +,-,/, %.
-
Some logical operators I know are: && (and), | | (or), ! (not), ?: (conditional).
- What are operators?
An operator operates on values, performs an action on values. - What binary operators do you know?
/ * + - - What logical operators do you know?
&& || !
-
Operators are elements that manipulates values.
-
Booleans
3.&&-or !
An operator performs some operation on single or multiple operands (data value) and produces a result.
Operators that use two values are called binary operators, while those that take one are called unary operators.
Multiplicative operators: multiplication(*), remainder(%), and division(/)
Additive operators: addition(+) and subtraction (-)
Shift operators: left shift(<<) and right shift (>>)
Relational operators: less than(<), less than or equal(<=), greater than(>), and greater than or equal(>=)
Equality operators: equality(==) and inequality(!=)
Bitwise operators: AND(&), OR(|), and XOR(^)
Logical operators: AND(&&) and OR(||)
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.
The || operator denotes logical βorβ . It produces true if either of the values given to it is true.
The ! operator logical βnotβ.
1. What are operators?
First of all you can distinguish operators by the number of arguments they take:
Unary operators take one argument, for example typeOf takes the name of a variable and returns its type.
Binary operators take two arguments and return one value, for example * takes two arguments a and b and returns the product of these arguments a * b.
Ternary operators take three arguments and return one value, for example the conditional operator:
condition ? expression1 : expression2
If the condition is true, it returns the value of expression1.
If the condition is false, it returns the value of expression2.
But there is also a classification of operators according to their use case:
Arithmetic Operators
Arithmetic operators use numeric values as their operands and return a single numerical value:
- β+β adds up two values to calculate the sum (but also serves as a positive sign, when used on a single value).
- β-β subtracts the second value from the first value to calculate the difference (but also serves as a negative sign, when used on a single value).
- β*β multiplies two values to calculate the product.
- β/β divides the first value by the second value to calculate the quotient.
- β%β returns the remainder when you divide the first value by the second value.
- β++β increments the value of a variable by 1.
- βββ decrements the value of a variable by 1.
Comparison Operators
A comparison operator is a binary operator that takes two operands and compares their values:
- β==β compares the left operand with the right operand and returns true if the values are equal. Otherwise it will return false.
- β!=β checks if the left operand is not equal to the right operand.
- β>β checks if the left operand is greater than the right operand.
- β<β checks if the left operand is less than the right operand.
- β>=β checks if the left operand is greater than or equal to the right operand.
- β<=β checks if the left operand is less than or equal to the right operand.
Logical Operators
A logical operator is used to determine the logic between two expressions. It takes in two operands and produces a single logical value. It returns a Boolean value if used with Boolean operands and vice versa:
- β&&β : logical AND.
- β||β : logical OR
- β!β : logical NOT
There are the bitwise versions of the logical operators as well.
Assignment Operators
An assignment operator is the operator used to provide a new value to the left operand according to the value of the right operand:
- β=β assigns the expression on the right to the variable on the left, for example a = b + c.
- β+=β assigns a sum to to the variable on the left, a += b is a shortcut for a = a + b.
- β-=β assigns a difference to to the variable on the left, a -= b is a shortcut for a = a - b.
- β*=β assigns a product to to the variable on the left, a *= b is a shortcut for a = a * b.
- β/=β assigns a quotient to to the variable on the left, a /= b is a shortcut for a = a / b.
- β%=β assigns a division remainder to to the variable on the left, a %= b is a shortcut for a = a % b.
Conditional (or Ternary) Operators
Conditional operators are used in evaluating a condition and return a value based on the evaluation of the condition:
- condition ? exp1 : exp2
It takes three operands and returns the value of exp1
if the condition is true
and the value of exp2
if the condition is false
.It is usually used as a shortcut to the if condition.
2. What binary operators do you know?
In the answer of question 1 many operators are already mentioned. Arithmetic operator are usually binary (with the exception that β+β and β-β can be used as the unary sign operator as well). But not all arithmetic operators are binary. For example Math.sign() or Math.abs() are operators, which only take one argument. All above mentioned comparism operators are binary. Logical operators are binary in case of β&&β and β||β, but not β!β, which is unary.
3. What logical operators do you know?
I know the locigal operators mentioned above (β&&β, β||β and β!β). However there are also bitwise logical operators in JavaScript, which execute the logical operation for each and every bit of each operand:
- β&β is a bitwise AND, for example 1101 & 0011 = 0001.
- β|β is a bitwise OR, for example 1001 | 0011 = 1011.
- β^β is a bitwise XOR, for example 1001 ^ 0011 = 1010.
- β~β is a bitwise NOT, for example ~1001 = 0110.
For further explanation and additional examples regarding Javascript bitwise operators please refer to https://www.w3schools.com/js/js_bitwise.asp.
Remark: Please note, that I could not mention all available operators of JavaScript.
- Operators are the actions that you want to preform on the Values. E.g. * / + -
- Greater than >, Less than <, Equal to ==.
- And &&, Or ||, Not !.
-
What are operators?
operators are used to assign values, compare values, perform arithmetic operations, and more. -
What binary operators do you know?
Binary operators perform the same arithmetic operations as operators when just with multiple values shown, ==, ++, Β±, -
What logical operators do you know?
! not. Thats it
-
Operators are logical functions assigned by symbols that tells to the values what to do and how to interact with each other
-
Multiplicative operators: multiplication (*), remainder (%), and division (/)
Additive operators: addition (+) and subtraction (-)
Shift operators: left shift (<<) and right shift (>>)
Relational operators: less than (<), less than or equal to (<=), greater than (>), greater than or equal (>=)
Equality operators: equality (==) and inequality (!=)
Bitwise operators: AND (&), OR (|), XOR (^) -
Logical operators: AND (&&) and OR (||)
1. What are operators?
Operators operate on Values. They are shown as sign, +, -, * etc.
Having an Operator between two values will produce a new value.
2. What binary operators do you know?
Additive Operators
- The Addition operator (
+
) - The Subtraction Operator (
-
)
Multiplicative Operators
- The
*
Operator - The
/
Operator - The
%
Operator
Relational Operators
- The Less-than Operator (
<
) - The Greater-than Operator (
>
) - The Less-than-or-equal Operator (
<=
) - The Greater-than-or-equal Operator (
>=
)
Equality Operators
- The Equals Operator (
==
) - The Does-not-equals Operator (
!=
) - The Strict Equals Operator (
===
)
Binary Logical Operators
- The and Operator (&&)
- The or Operator (||)
3. What logical operators do you know?
Binary Logical Operators
- The and Operator (&&)
- The or Operator (||)
Unary Logical Operators
- The not Operator ( ! )
Ternary Logical Operator
- The conditional Operator (?)
Impressive answer!
1.An operator performs some operation on single or multiple operands (data value) and produces a result.
2. Binary operators ( & , ^ , | )
3. Logical operators ( && , || )
Operators are tools that work on values. We can compare, add, multiply, divide, subtract and so on.
+, -, /, *, %, ==, ===, !=, <, >, >=, <=
||, &&, ! (or, and, not)
- What are operators?
Operators in a sense are βverbsβ, they define what will happen to values that are entered into the JS program.
- What binary operators do you know?
There are arithmetic operators(+, -, /, *, %), comparison operators(==, !=, ===, !==, <, >, <=, >=) and logical operators(see below).
- What logical operators do you know?
β&&β, β||β, β!β
Thank you! You can guess that it took me some time to edit this post, but this also helped me learning some more details about operators. I covered not every operator, but at least the most important ones.
$
1- operator is an object that is capable of manipulating a value. e.g. *, /, %, ++, β
increment, decrement, addition, subtraction or ==, ===
Operators are used to assign values, compare values, perform arithmetic operations . etc.
2- Arithmetic, relational, logical, string, comparison and assignment operators.
3- and , or, not > &&, ||, !
if(a > b || c > d) { }
if(a > b && c > d) { }
if(a !== b) { }
[/quote]