r/ProgrammerHumor • • Mar 20 '24

Meme areJSDevsActuallySane

Post image
14k Upvotes

554 comments sorted by

View all comments

Show parent comment

2

u/Frown1044 Mar 21 '24

Type coercion actually makes sense here, just not in every single context.

In JS you can write code like new RegExp(/abcdef/g). The regex inside is an object, not a string. It can get converted to its equivalent string "/abcdefg/g" however.

Likewise other things that implement .toString() can return valid input.