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

javascript equality

18 === 18 // true
18 === 19 // false
`18` == 18 // true
`18` === 18 // false

// == : loose equality operator (date type IS NOT relevant)
// === : strict equality operator (date type IS relevant)

// Note: the same applies for not equal
`18` != 18 // false
`18` !== 18 // true
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 :: nextjs query parameter 
Javascript :: javascript change input value jquery 
Javascript :: binary search javascript 
Javascript :: geojson 
Javascript :: removes null and false values from an array 
Javascript :: jquery once 
Javascript :: get nearest location based on latitude and longitude javascript 
Javascript :: operators in js 
Javascript :: send post request 
Javascript :: useScroll 
Javascript :: async foreach 
Javascript :: js remove all except numbers 
Javascript :: classic asp get json from file 
Javascript :: select the items from selectors in .map reactjs 
Javascript :: socketio connect websockets 
Javascript :: react time input 
Javascript :: mongo connect npm 
Javascript :: C# Convert DataTable to Json File using Newtonsoft.Json DLL 
Javascript :: type of angular 
Javascript :: react native gif dont work 
Javascript :: react native use route params 
Javascript :: code for javascript message box 
Javascript :: sum index of an array javascript 
Javascript :: javascript find matching elements in two arrays 
Javascript :: next-dev.js?3515:32 Warning: Prop `className` did not match. Server Client 
Javascript :: Material-ui Accessible icon 
Javascript :: hex decima to binary js 
Javascript :: swap numbers in javascript 
Javascript :: express.js hello world 
Javascript :: how to comment out code in react js 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =