In JavaScript, there are several data types that you can use to store different kinds of values. Understanding these data types and how they are compared is crucial for writing efficient and error-free code. In this tutorial, we will explore the different data types in JavaScript and discuss how they are compared.
JavaScript has six primitive data types: string, number, boolean, null, undefined, and symbol. These data types are immutable, meaning that their values cannot be changed once they are created. JavaScript also has an object data type, which is a reference type that can hold complex values like arrays, functions, and objects.
When comparing values in JavaScript, it is important to understand the difference between strict and loose comparison. Strict comparison (===) compares both the value and the type of the operands, while loose comparison (==) only compares the values.
Let’s start by looking at how string values are compared in JavaScript. Strings are compared based on their Unicode value, with the comparison being case-sensitive. For example, “abc” is considered less than “xyz” because “a” has a lower Unicode value than “x”. When using the strict equality operator (===), both the value and type of the strings are compared. For example, “1” === 1 will return false because one is a string and the other is a number.
Next, let’s look at number values in JavaScript. Numbers are compared based on their numerical value. When using the strict equality operator (===), both the value and type of the numbers are compared. For example, 1 === 1 will return true because both values are the same and of the same type.
Boolean values in JavaScript are compared based on their truthiness. When using the strict equality operator (===), both the value and type of the booleans are compared. For example, true === true will return true because both values are true and of the same type.
Null and undefined are special data types in JavaScript that represent the absence of a value. When comparing null and undefined values, the loose equality operator (==) will return true, but the strict equality operator (===) will return false because they are of different types.
Symbols are a new data type introduced in ECMAScript 6 and are unique and immutable values that can be used as object keys. When comparing symbols, both the value and the type are compared using the strict equality operator (===). Symbols are never equal to any other value, even if they have the same value.
When comparing objects in JavaScript, the comparison is done by reference. This means that two objects are considered equal only if they refer to the same object in memory. When using the strict equality operator (===), two objects with the same properties and values will still return false if they are not the same object in memory.
In conclusion, when comparing values in JavaScript, it is important to understand the data types being used and the difference between strict and loose comparison. By being mindful of how JavaScript compares data types, you can write more efficient and error-free code.
Bro this is Really paid leave course
I have already watched JavaScript tutorial on a other channel. But I made to much mistakes in JavaScript. After watching your course I can understand JavaScript easy. Your Way of Teaching is Amazing. You teach Everything perfectly. Thanks for your effort
Big fan from Pakistan ❤❤❤❤❤❤❤
A very detailed playlist enjoyed alot within investigation study
00:02 Comparison of datatypes in JavaScript
01:10 Comparing data types in JavaScript
02:19 When comparing values in JavaScript, make sure their data types are the same.
03:27 The comparison and equality operators in JavaScript have different behaviors.
04:36 JavaScript converts null to zero during comparison.
05:44 Comparison and equality checks in JavaScript
06:53 JavaScript datatype comparison with double and triple equal
07:50 Avoid confusing conversions and comparisons in JavaScript
If null is converted to zero, why does null == 0 return false?
00:02 Comparison of datatypes in JavaScript
01:10 Comparing data types in JavaScript
02:19 When comparing values in JavaScript, make sure their data types are the same.
03:27 The comparison and equality operators in JavaScript have different behaviors.
04:36 JavaScript converts null to zero during comparison.
05:44 Comparison and equality checks in JavaScript
06:53 JavaScript datatype comparison with double and triple equal
07:50 Avoid confusing conversions and comparisons in JavaScript
Thank you to Hitesh Sir for making such an awesome video! 🙌🎥 Brushing up on my JS knowledge 🧠
sir ,
1. console.log(null > 0);
2. console.log(null == 0); 3. console.log(null >= 0 );
apne bola ki 3 wale log me null ki value apne app 0 conclude kr leta hai to baki 1,2 , log me kyu nhi krta hai ??????
great work
null=0
null==0 =>false why??
00:02 Comparison of datatypes in JavaScript
01:10 Comparing data types in JavaScript
02:19 When comparing values in JavaScript, make sure their data types are the same.
03:27 The comparison and equality operators in JavaScript have different behaviors.
04:36 JavaScript converts null to zero during comparison.
05:44 Comparison and equality checks in JavaScript
06:53 JavaScript datatype comparison with double and triple equal
07:50 Avoid confusing conversions and comparisons in JavaScript
Great Content!!!
sir typescript hindi me khab aayega
nice and helpful tutorial.
Hi
Sir g 4:18 mins pr jo note aap ney diya wo practically different hai jo aap kr k bta rhay, It's confusing please help
bhai chai kaha h aaap ki
Nice
Thank you Sir
But Sir the comparison between "2" and "j" console.log("2">"j") is false because of 2 unicode 50 and j unicode is 106 , since 2 comes before j that's why "2" is not greater than "j" right?
1