JavaScript Conditional (or) Ternary Operator

Card image cap

JavaScript Operator Definition

An operator that performs some operation on single or multiple operands and produces a result is called Operators.

An Operators are symbols or keyword that enable JavaScript to perform some sort of actions.


JS Conditional Operator (or) Ternary Operator

Conditional Operator is also called as Ternary Operator

Conditional operator first evaluates an expression for a true or false value and then execute one of the two given statements depending upon the result of the evaluation.

Syntax:


	if(operand1 conditional operator operand2)? statement1:statement2

Example:


	if(a==b)?1:0


Bitwise Operator:

JavaScript bitwise operators evaluate and perform specific bitwise (32 bits either zero or one) expression.

Operator Sign Description
Bitwise AND & Return bitwise AND operation for given two operands.
Bitwise OR | Return bitwise OR operation for given two operands.
Bitwise XOR ^ Return bitwise XOR operation for given two operands.
Bitwise NOT ~ Return bitwise NOT operation for given operand.
Bitwise Shift Left << Return left shift of given operands.
Bitwise Shift Right >> Return right shift of given operands.
Bitwise Unsigned Shift Right >>> Return right shift without consider sign of given operands.

Example:

Result:

Bitwise AND :0
Bitwise OR :15
Bitwise XOR :15
Bitwise NOT :-6
Bitwise Shift Left :40
Bitwise Shift Right :2
Unsigned Shift Right :2

Read Also:

Card image cap