📎 Webclip
11 Powerful JavaScript One-Liners Worth Knowing
The page collects 11 short JavaScript utilities and shows the single-line code for each one. The examples cover string counting, object emptiness, async waiting, date differences, redirects, touch support, DOM insertion, shuffling, selected text, random booleans, and array averages.
Reading notes#
characterCountsplits a string by a given character and uses the array length minus one.isEmptychecks that an object has no own keys and that its constructor isObject.waitcreates a promise and resolves it withsetTimeoutafter a given time.daysBetweenconverts the absolute difference between two dates from milliseconds into days.redirectsetslocation.hrefto send the browser to another URL.touchSupportedchecks whether the document supportstouchstart.insertHTMLAfterusesinsertAdjacentHTML('afterend', html)to place HTML after an element.shuffleusesarr.sort(() => Math.random() > 0.5)to randomize array order.getSelectedTextreturns the browser selection as a string.getRandomBooleanreturnstrueorfalsewith equal probability.averagesums array values withreduceand divides byarr.length.
