Skip to content

Instantly share code, notes, and snippets.

Created January 20, 2023 12:05
What would you like to do?
Strict and Loose Equality Example in JavaScript
// Use strict equality when comparing variables of the same type
let age = 25;
let legalAge = 21;
console.log(age === legalAge); // false
// Use loose equality when comparing variables that may be a string or a number
let input = "25";
let number = 25;
console.log(input == number); // true
// Use loose equality when comparing a variable to null or undefined
let name;
console.log(name == undefined); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment