DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Languages
  4. In Defense of JavaScript Oddities

In Defense of JavaScript Oddities

Men and women of the developer jury! JavaScript stands accused of being 'odd.' We shall now hear from JavaScript's defense!

Andrea Chiarelli user avatar by
Andrea Chiarelli
·
Feb. 05, 19 · Tutorial
Like (2)
Save
Tweet
Share
7.65K Views

Join the DZone community and get the full member experience.

Join For Free

My fellow members! Ladies and gentlemen of the court!

My client has too often unfairly been an object of ridicule and public derision. Too many times developers, especially the developers of other languages, have made fun of him and laughed at him. They insist on considering it, so to speak, weird, bizarre, geeky.

Most of the reasons for these attacks on my client are based on alleged oddities such as

[] == ![]    // -> true

or

NaN === NaN             // -> false
Math.max()>Math.min()   // -> false

or even

[] == ''   // -> true
[] == 0    // -> true
[''] == '' // -> true
[0] == 0   // -> true
[0] == ''  // -> false
[''] == 0  // -> true

What are we talking about? What are the oddities?

What’s strange about the fact that, if you submit this request to my client

{} + []

he answers with “0”? Where’s the oddity?

Perhaps the strangeness is not so much in the answer as in the question. How can you expect, if you ask my client such a shabby question, to get an answer that makes sense? My client answers “0,” but he might as well answer “42.” I do not see why a different answer could be considered less strange than this one.

Perhaps he’d be better off doing what others languages do in this situation, that is, raising an exception, getting angry, and probably insulting their interlocutor? No, my client has a sense of humor and has no intention of offending anyone. He realizes the absurdity of the request and responds in tone, with an answer of the same tenor.

The classic objection is that not only is my client strange, but he is not even consistent, since to the following request

[] + {}

he does not respond again with “0,” but with “[object Object].”

Even here, where is the strangeness? Who said that the “+” operation between an array and an object is commutative? No one is surprised that the result of “foo” + “bar” is different from the result of “bar” + “foo.” But if my client gives a different answer when you change the order of the operands, then he is strange.

Another objection against my client is that it is not a true OOP language because it has no classes, or rather the classes it has are not real classes. First: who said that an OOP language must have classes? Second: OK, my client has been a little ambiguous in supporting the new keyword and the class keyword. But he did it in good faith, to feel equal to the other languages that snubbed him.

I can’t hide the fact that my client is a bit different from the other languages, but not so different as to deserve mockeries and insults.

The truth is that those who accuse my client of strangeness do not know him and do not want to try knowing and understanding him. They are so used to rigid languages and without the slightest sense of humor (I would dare to say, without a soul) that they mistake jokes with strangeness and inconsistencies.
But if only these people tried to know him better, they would discover that everything has a reason, that probably the issue is not in the answers that my client gives, but in the questions asked by developers.

JavaScript dev Requests Object-oriented programming Object (computer science) Fellow (computing) Data structure

Published at DZone with permission of Andrea Chiarelli. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • A Beginner's Guide to Back-End Development
  • Best Practices for Writing Clean and Maintainable Code
  • AIOps Being Powered by Robotic Data Automation
  • Do Not Forget About Testing!

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: