3

Add equals() method to the String class?

 1 year ago
source link: https://es.discourse.group/t/add-equals-method-to-the-string-class/1442/3
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Add equals() method to the String class?

I'm fairly new to web dev and my expertise is in C/C++, Java, and Python. I am perplexed by the complexity of comparing two strings in JavaScript. Look no further than stackoverflow. 18 Because I come from a C/C++/Java background, I oftentimes wonder why JavaScript doesn't have a ".equal()" method like Java and other languages.

In my opinion, it seems like a no-brainer decision considering that one of JavaScript's founding principles was to have a degree of familiarity with other programming languages. Furthermore, adding one of the above methods will temporarily solve the "===" and "==" confusion that is rampant in the JavaScript community. It has potential to save programmers from costly bugs that can result from the confusion between "==" and "===".

Example:

var drink = "coffee";
if (drink.equals("coffee")) {
    document.write(true);
}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK