What are Boolean Data Types and Comparison Operators? (🧵)
Larry’s age is < 25 years, so we set the variable: isAgeLessThan25 to true, because that's correct.
Similarly, we set : isSalaryMoreThan200K variable to false because the salary is $120,000!
That's it for the boolean data type! Now here's where comparison operators come in.
Similarly, we set : isSalaryMoreThan200K variable to false because the salary is $120,000!
That's it for the boolean data type! Now here's where comparison operators come in.
✨Comparison Operators
Boolean standalone isn't very useful. But they are the output of any comparison you make. They dictate a lot of things & you will see them once you learn loops and control flows. For now, it is imperative that you understand comparisons & what they return.
Boolean standalone isn't very useful. But they are the output of any comparison you make. They dictate a lot of things & you will see them once you learn loops and control flows. For now, it is imperative that you understand comparisons & what they return.
You'd have to use the “>”, "<" symbols for checking more than or less than a certain value.
To check if salary is equal to 120000, you'd have to use the “==” operator. It basically checks whether the value on the LHS is equal to the RHS.
To check if salary is equal to 120000, you'd have to use the “==” operator. It basically checks whether the value on the LHS is equal to the RHS.
Note very carefully that, while in line 12, 120000 is a Number data type, in line 16 it is a String data type because it is inside double-quotes.
If your instinct was to say, that the output will be false because you cannot compare different data types, you'd usually be right!
If your instinct was to say, that the output will be false because you cannot compare different data types, you'd usually be right!
However if JS sees you do something like you did in line 16, it will understand that you actually wanted to compare numbers. It'll convert “120000” into 120000 and the RHS String type into Number type and then return true!
This is called ✨Type Conversion✨. Try it out.
This is called ✨Type Conversion✨. Try it out.
Conclusion
In this blog, we saw a lot of detail about the Object. data type. We also learned about Boolean data types and the Comparison operators and we touched upon type conversions. And that’s pretty much it for this thread.
In this blog, we saw a lot of detail about the Object. data type. We also learned about Boolean data types and the Comparison operators and we touched upon type conversions. And that’s pretty much it for this thread.
Loading suggestions...