Skip to content

Instantly share code, notes, and snippets.

@dmgarland
Created October 9, 2013 14:35
Show Gist options
  • Select an option

  • Save dmgarland/6902298 to your computer and use it in GitHub Desktop.

Select an option

Save dmgarland/6902298 to your computer and use it in GitHub Desktop.
Equals method in Javascript
String.prototype.equals = function(s) {
if(typeof(s) == "object") {
return this.valueOf() === s.valueOf();
}
else if(typeof(s) == "string") {
return this.valueOf() === s;
}
else {
return undefined;
}
};
console.log("123".equals("123"));
console.log("123".equals(new String("123")));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment