Scarlett Ideas Back to catalog
What is Triple Equal in JavaScript?
Aug 28, 2026 Scarlett

Javascript Inequality: Understanding 'Not Equal' Operators

The concept of inequality in programming is fundamental to comparisons, logarithms, and algorithms. JavaScript, a versatile programming language, employs severa...

The concept of inequality in programming is fundamental to comparisons, logarithms, and algorithms. JavaScript, a versatile programming language, employs several ways to implement not equal statements. Understanding these is pivotal for any developer's skillset.

What is Triple Equal in JavaScript?

Inequality in JavaScript, designated by the strict not equal operator `!==`, ensures that both the type and value of variables are different. This is contrasted with the loose not equal operator `!=`, which only compares values regardless of type.

Javascript NULL VS Empty VS Undefined

Not Equal Operators

The `!==` operator is JavaScript's most-used inequality operator, designed to return `true` when the types or values of two variables differ.

Don't Make Javascript Equality Look Worse Than It Is

Remember that JavaScript is dynamically or loosely typed. Thus, when comparing with `!=`, any non-strict comparisons will first attempt to convert the types of the variables to comparable types.

Strict Not Equal (`!==`) vs Loose Not Equal (`!=`)

Writing Conditional Statements in JavaScript

The key difference lies in type conversion. Consider a scenario where `var x = 5` and `var y = "5"`. Writing `console.log(x != y)` will return `true` because the values are not the same. However, writing `console.log(x !== y)` also returns `true` despite the types being similar because JavaScript considers type in strict comparison.

In the example above, for the `!=` operator, JavaScript performs type coercion – it converts both x's value and y's value to the same type before comparison, usually converting numbers to strings. For `!==`, it maintains the true type of each value.

Not Equals in Various Data Types

JavaScript Cheat Sheet

Testing `!==` across various JavaScript data types can clarify misunderstandings. For objects and arrays, the strict not equal operator (`!==`) considers them equal if they have the same reference. Otherwise, they're not equal.

For `null` and `undefined`, the operator `!==` behaves the same way because it compares not only the value but the type, distinguishing `'null'` from `'undefined'`.

In Practice: Not Equal in JavaScript

JavaScript Triple Equals Sign VS Double Equals Sign – Comparison Operators Explained with Examples

Let's recap with examples. A common usage of not equals in JavaScript is in control flow statements, especially `if` statements. For instance, in user-validation or routing logic:

```javascript if (userAge !== undefined && userAge < 18) { console.log("You are not eligible to vote.") } ```

Variable declarations in JavaScript
Comparison operators in JavaScript
What's the difference between a double equal and a triple equal in JavaScript? #animecoders
Functions in Javascript
JavaScript Semicolons: To Use or Not to Use? πŸ€”
Should You Stop UsingΒ .forEach() in Your JavaScript Code?
How to get last items from an array in JavaScript
javascript and python
Logical Operators In JavaScript πŸ“”πŸš€

Operators in Function Arguments

The `!==` operator also plays a role in function arguments. Often, for equality checks or when you want to allow specific values, it is important to use `!==` instead of `!=` to avoid type coercion issues.

Consider a function that accepts a string or a number as an argument but not `null` or `undefined`:

```javascript function greet(name) { if (name !== null && name !== undefined && name !== "") { console.log(`Hello, ${name}!`); } } ```

Finally, while working with JavaScript's not equal operators, remember that expressions might sometimes surprise you due to JavaScript's dynamic typing. Always confirm the specific behavior in your development environment to avoid bugs and ensure your code's reliability.

The journey of learning or reviewing `!==` and `!=` operators in JavaScript might seem exacting but is rewarding. Now that you grasp their nuances, apply concepts in your code and you'll see an improvement in both readability and the efficacy of your code.

More shots

What is Triple Equal in JavaScript?
What is Triple Equal in JavaScript?
Javascript NULL VS Empty VS Undefined
Javascript NULL VS Empty VS Undefined
Don't Make Javascript Equality Look Worse Than It Is
Don't Make Javascript Equality Look Worse Than It Is
Writing Conditional Statements in JavaScript
Writing Conditional Statements in JavaScript
JavaScript Cheat Sheet
JavaScript Cheat Sheet
JavaScript Triple Equals Sign VS Double Equals Sign – Comparison Operators Explained with Examples
JavaScript Triple Equals Sign VS Double Equals Sign – Comparison Operators Explained with Examples
Variable declarations in JavaScript
Variable declarations in JavaScript
Comparison operators in JavaScript
Comparison operators in JavaScript

Related topics