Equality & Relational Operators

Desiah BarnettDesiah Barnett
2 min read

Lets chat a little bit about Equality Operator. Boolean variables(expressions) return true or false values. When it comes to comparison operators in JavaScript there are four equality operators.

Strict Equality Operators, Strict Inequality Operators, Loose Equality Operators, and Loose Inequality Operators. We are only going to focus on Strict Equality/Inequality Operators .

Lets talk about Strict Equality Operators ( ===). These operators return a value of true without a type conversion taking place. The data has to match on both sides of the expression in order for it to return true.

39 === 39;
console.log(39 === 39);
you will get the value "true"

39 === `39`;
console.log(39 === `39`)
you will get the value "false"

Desiah ==== Desiah
console.log(Desiah === Desiah)
you will get the value "true"

Desiah === `Desiah`
console.log(Desiah === `Desiah`)
you will get the value "false"

A Boolean expression returns false when comparing two values that are not the same you. Lets move on to Strict Inequality Operators.

Strict Inequality Operators return value of true when two data types are different. Lets look at some examples.

777 !== 777
console.log(777 !== 777)
you will get value "false". That is because both values are the same.

555 !== 888
console.log(777 !== 888)
you will get value "true". That is because both values are different.

Lets focus on all four relational operators:

greater than ( > ),

greater than or equals ( >= )

less than ( < )

less than or equal ( <= )

999 > 44;
console.log(999 > 23)
// => true

"9" >= "66";
console.log("9" >= "66")
// => true. In this case it is character by character based.
// 9 is bigger than 4 so it will return true. That applies on
// when comparing strings.

9 < 444;
console.log(9 < 444);
// => true 9 is bigger than 444

When comparing number against non- numbers, a type conversion will take place. A Type Conversion is when two data types that are different are converted so they are the same.

333 >= "Divine"
console.log(333 >= `Divine`)
// it will return false because a type conversion can not be made.
// This is because both values are not numbers.
0
Subscribe to my newsletter

Read articles from Desiah Barnett directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Desiah Barnett
Desiah Barnett

Desiah Barnett is a passionate educator, EdTech founder, and advocate for diversity and inclusion in the tech industry. As the visionary behind CoraHack she is dedicated to providing accessible, hands-on tech education in software engineering, data science, AI, and cybersecurity. With a strong focus on empowering underrepresented communities, Desiah works to break down barriers and create opportunities for individuals from all backgrounds to thrive in the digital economy. Her leadership is driven by the belief that real change starts with fearless action, and she is committed to ensuring that the tech space is inclusive, equitable, and accessible to everyone.