If you just used TypeScript
You know what has a concept of optional arguments? … Type Systems. And as type systems go, TypeScript is a pretty darn good one. Just try the following in TypeScript (go ahead … click me and see for yourself):
As tricks go its actually a potentially disastrous one. I’d be scared to put that into an existing project and pushing it to production. However moving an existing project to TypeScript …. I’d do it in a heartbeat🌹
All that said. If you want to use that trick in raw JS, I wouldn’t judge you.