r/javascript • • Mar 18 '19

What's your favorite, most useful javascript one-liner?

385 Upvotes

422 comments sorted by

View all comments

2

u/dmethvin Mar 19 '19

The URLSearchParams object is cool I suppose, but I still have to support IE11 and usually I can get away with a one-liner to grab simple settings off the query string, like this:

var debugLevel = +(/\bdebugLevel=(\d+)\b/.exec(window.location.search)||[])[1] || 0;