Top 5 one liners in JavaScript

<p>In the world of JavaScript, I&rsquo;m the magician of one-liners, simplifying the complex with elegance.</p> <h2>1.Copy to Clipboard</h2> <p>In web apps, copy to clipboard is rapidly rising in popularity due to its convenience for the user.</p> <pre> const copyToClipboard = (text) =&gt; navigator.clipboard?.writeText &amp;&amp; navigator.clipboard.writeText(text); // Testing copyToClipboard(&quot;Hello World!&quot;); </pre> <h2>2.Generate Random Color</h2> <p>Does your application rely on random color generation? Look no further, the following snippet got you covered!</p> <pre> const generateRandomHexColor = () =&gt; `#${Math.floor(Math.random() * 0xffffff).toString(16)}`; </pre> <h2>3.Detect Dark Mode</h2> <p>With the rising popularity of dark mode, it is ideal to switch your app to dark mode if the user has it enabled in their device. Luckily, media queries can be utilized for making the task a walk in the park.</p> <pre> const isDarkMode = () =&gt; window.matchMedia &amp;&amp; window.matchMedia(&quot;(prefers-color-scheme: dark)&quot;).matches; // Testing console.log(isDarkMode()); </pre> <h2>4.Scroll To Top</h2> <p>Beginners very often find themselves struggling with scrolling elements into view properly. The easiest way to scroll elements is to use the scrollIntoView method. Add behavior: &quot;smooth&quot; for a smooth scrolling animation.</p> <p><a href="https://medium.com/@vishalkrishna8/top-5-one-liners-in-javascript-d9555bed7ece">Click Here</a></p>