JavaScript is a very interesting programming language.
It is easy and quick to code, runs immediately in runtimes like the web or Node.js, and is quite fast despite being a dynamic type language.
However, the freedom of JavaScript seems to be somewhat controversial.
For example, many developers believe that strict comparison is essential when comparing values.
Implicit Casting in JavaScript
I like to use implicit casting when writing JavaScript. All values in JavaScript can be implicitly cast to boolean.
True
1, -1 // non-zero number
" " // non-empty string
{}, [], function() {}, () => {}, this // non-null object
False
0 // zero
"" // empty string
null // null object
undefined // undefined
Loose Comparison in JavaScript
Loose comparison in JavaScript casts the compared values to the number type if they are of different types. Object types are compared by their address values, but the equality comparison of null and undefined is exceptionally treated as true.
123 >= "00123" // 123 >= 123
2 == true // 2 == 1
{} == {} // *{} == *{}
null == undefined // true
null >= undefined // *null >= undefined
Conclusion
JavaScript is a very liberal language, and the features of JavaScript such as implicit casting may seem confusing at first, but I personally think this is one of the advantages of JavaScript.
Thank you.