denysdovhan / wtfjs

🤪 A list of funny and tricky JavaScript examples
http://bit.ly/wtfjavascript
Do What The F*ck You Want To Public License
34.75k stars 2.55k forks source link

"Addition of Regexps" is invalid #177

Closed towc closed 3 years ago

towc commented 3 years ago

The code presented is

// Patch a toString method
RegExp.prototype.toString =
  function() {
    return this.source;
  } /
  7 /
  -/5/; // -> 2

But when running, that's just NaN because it divides a function by 7.

What you probably meant is:

// Patch a toString method
RegExp.prototype.toString =
  function() {
    return this.source;
  };
/7/ - /5/; // -> 2
towc commented 3 years ago

also, can I suggest you use --> 2 and similar for all the comments meant to show the return value, instead of the standard //? Would add to the quirky experience

denysdovhan commented 3 years ago

This is probably broken because of Prettier :\

denysdovhan commented 3 years ago

Already fixed. Thanks for reporting!