DEV Community

Cover image for Is JavaScript's freedom a strength or a weakness?
Yeom suyun
Yeom suyun

Posted on

2 2 1 1 1

Is JavaScript's freedom a strength or a weakness?

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
Enter fullscreen mode Exit fullscreen mode

False

0 // zero
"" // empty string
null // null object
undefined // undefined
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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.

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

Top comments (3)

Collapse
 
artxe2 profile image
Yeom suyun

I recommend JavaScript for beginners, but I think it is definitely easier to learn JavaScript if they already know Java.

Cloudinary image

Video API: manage, encode, and optimize for any device, channel or network condition. Deliver branded video experiences in minutes and get deep engagement insights.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay