Strict and Loose Equality Example in JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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