JavaScript: Comparison and Logical Operators

Comparison Operators:
Comparison operators are used in logical statements to determine equality or difference between variables or values.

Javascript Comparision Operators

Comparision Operators

Logical Operators:
Logical operators are used to determine the logic between variables or values.

Javascript Logical Operators

Logical Operators

Conditional (Ternary) Operator:
JavaScript also contains a conditional operator that assigns a value to a variable based on some condition.
Syntax:
variablename = (condition) ? value1:value2

Comparing Different Types:
Comparing data of different types may give unexpected results.

When comparing a string with a number, JavaScript will convert the string to a number when doing the comparison. An empty string converts to 0. A non-numeric string converts to NaN which is always false.

Javascript Comparision Different Types

Comparision Different Types


Myntra CPS

Bitwise Operators:
Bit operators work on 32-bit numbers.
Any numeric operand in the operation is converted into a 32-bit number.
The result is converted back to a JavaScript number.
Example:
x = 5 & 1;
The result in x:
1

Javascript Bitwise Operators

Bitwise Operators


PaisaBazaar IN CPL - Credit Card

Share this:
Share