Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js comparison operators

Javascript Comparison Operators
== 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
Comment

JavaScript Comparison Operators

Operator	Description	Example
==	Equal to: returns true if the operands are equal	x == y
!=	Not equal to: returns true if the operands are not equal	x != y
===	Strict equal to: true if the operands are equal and of the same type	x === y
!==	Strict not equal to: true if the operands are equal but of different type or not equal at all	x !== y
>	Greater than: true if left operand is greater than the right operand	x > y
>=	Greater than or equal to: true if left operand is greater than or equal to the right operand	x >= y
<	Less than: true if the left operand is less than the right operand	x < y
<=	Less than or equal to: true if the left operand is less than or equal to the right operand	x <= y
Comment

Comparison operators in JavaScript

// equal operator
console.log(2 == 2); // true
console.log(2 == '2'); // true

// not equal operator
console.log(3 != 2); // true
console.log('hello' != 'Hello'); // true

// strict equal operator
console.log(2 === 2); // true
console.log(2 === '2'); // false

// strict not equal operator
console.log(2 !== '2'); // true
console.log(2 !== 2); // false
Comment

Javascript comparison

const num1 = 450;
const num2 = 350;
const num3 = 1000;

if (num1 > num2 && num1 > num3) {
    console.log("num1 is bigger then num2 and num3");
} else if (num2 > num1 && num2 > num3) {
    console.log("num2 is bigger num1 and num3");
} else {
    console.log("num3 is bigger then num1 and num2");
}
//Output: num3 is bigger then num1 and num2
Comment

JavaScript Comparison and Logical Operators

if (age < 18) text = "Too young to buy alcohol";
Comment

what are the comparison operators in javascript

<, >, <=, >=, ==, ===, !=, !==
Comment

PREVIOUS NEXT
Code Example
Javascript :: jspdf create table 
Javascript :: javascript filter map array of objects 
Javascript :: js local storage 
Javascript :: use await in for each 
Javascript :: new Date().now 
Javascript :: jquery disable all forms 
Javascript :: Shopify.formatMoney 
Javascript :: node get current user 
Javascript :: jsx babel webpack 
Javascript :: jquery find table from td 
Javascript :: react native navigation shared element 
Javascript :: remove element onclick javascript 
Javascript :: jquery datepicker on multiple input fields 
Javascript :: mongodb empty an array field 
Javascript :: sequelize max 
Javascript :: discord.js get user by username 
Javascript :: javascript remove string between 
Javascript :: javascript max 
Javascript :: axios post nuxt 
Javascript :: jQuery load() Method 
Javascript :: trigger jquery 
Javascript :: how to run a bash script with node js 
Javascript :: dynamic copyright year javascript 
Javascript :: react js http post 500 internal server error 
Javascript :: add days to date javascript dd/mm/yyyy in input date 
Javascript :: javascript reverse each string element in array 
Javascript :: unix to time in javascript 
Javascript :: volume slider javascript 
Javascript :: route parameter in node 
Javascript :: axios forward 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =