forked from aayushyadavz/JavaScript-Full-Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Learnt about how to compare data types & what's the best practice of the comparison.
- Loading branch information
1 parent
e67a87f
commit 560fc58
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// 4. Comparisons | ||
|
||
// (i) Comparisons with same Data Types, | ||
// console.log(2 > 1); // Output : true | ||
// console.log(2 >= 1); // Output : true | ||
// console.log(2 < 1); // Output : false | ||
// console.log(2 == 1); // Output : false | ||
// console.log(2 != 1); // Output : true | ||
|
||
/* Note : Whenever we compare value then we should keep in mind that both value should | ||
have same Data Types. */ | ||
|
||
// ---------------------------------------------------------------------------------------------- | ||
|
||
// (ii) Comparisons on different data types, | ||
// console.log("2" > 1); // Output : true | ||
// console.log("02" > 1); // Output : true | ||
|
||
/* Note : These comparisons some times do not give predictible outcomes, that's why we should | ||
compare same Data Types values. */ | ||
|
||
// console.log(null > 0); // Output : false, (0 > 0) | ||
// console.log(null == 0); // Output : false | ||
// console.log(null >= 0); // Output : true (0 >= 0) | ||
|
||
/* Note : Comparisons (<,>,<=,>=) and Equality check (==) works diffrently, | ||
Comparisons convert null into a number, treating it as 0. */ | ||
|
||
// console.log(undefined == 0); | ||
// console.log(undefined < 0); | ||
// console.log(undefined > 0); | ||
// In all the cases it will give false. | ||
|
||
/* **************************************Strict Check******************************************** | ||
(===) Triple Equal : Checks values as well as their Data Types. */ | ||
|
||
console.log("2" === 1); // Output : false | ||
|
||
|
||
|