Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Revisions

2 of 2
Commonmark migration

Exception abusing

in case string/character literals are prohibited, you can use a try catch block:

try{something0}catch(e){str=e.message.split(0)[0]}

now str equals "something"

if more strings are needed you can chain it with a number (e.g. zeros)

try{something0foo0bar0}catch(e){arr=e.message.split(0)}

now arr equals ["something", "foo", "bar", " is not defined"]

bebe
  • 4.2k
  • 2
  • 21
  • 21

AltStyle によって変換されたページ (->オリジナル) /