What are javascript operators?

 JavaScript Operators:

Javascript operators be a symbols related from the math, operators worked with one or multiple operands (Operands means the constants or variables).

Operands Operator operands Operator operands Then Results

As: 3 - 2 + 10 = 11

Javascript Operators are following :
  1. Arithmetic Operators
  2. Assignment Operators
  3. Comparison Operators
  4. Logical (Relational) Operators
  5. Conditional (ternary) Operators

1. JavaScript Arithmetic Operators

OperatorDescription
+Addition
-Subtraction
*Multiplication
/Division
%Modulus (Remainder)
++Increment
--Decrement

2. JavaScript Assignment Operators

OperatorExampleSame As
=x = yx = y
+=x += yx = x + y
-=x -= yx = x - y
*=x *= yx = x * y
/=x /= yx = x / y
%=x %= yx = x % y

3. JavaScript Comparison Operators

OperatorDescription
==equal to
===equal value and equal type
!=not equal
!==not equal value and not equal type
>greater than
<less than
>=greater than or equal to
<=less than or equal to
?ternary operator

4. JavaScript Logical (Relational) Operators

OperatorDescription
&&logical and
||logical or
!logical not
Usage of the && Operator
ExampleOperand 1Operand 2Result
(2<3)&&(4>2)truetruetrue
(2<3)&&(4<2)truefalsefalse
(3<2)&&(4>2)falsetruefalse
(3<2)&&(4<2)falsefalsefalse

If have anyone operands false then result surly would be "false"

Usage of the || Operator
ExampleOperand 1Operand 2Result
(2<3) || (4>2)truetruetrue
(2<3) || (4<2)truefalsetrue
(3<2) || (4>2)falsetruetrue
(3<2) || (4<2)falsefalsefalse

If have anyone operands true then result surly would be "true"

5. JavaScript Conditional (ternary) Operators

Ternary Operator: we indicate from the ? symbol. This is same as if else condition but we can use this in a single line as syntax is below:

condition ? expression1 : expression2

Expression1 means "true" value and expression2 means "false" value always.

Ternary Operator Example:

var age = 15;
var ticket = (age > 12) ? 100 : 50;
console.log(ticket); // 100

 


No comments:

Note: Only a member of this blog may post a comment.

Copyright Reserved to Anything Learn. Powered by Blogger.