20 Mind Blowing JavaScript Snippets 🤯
One line JavaScript snippets to boost up your productivity. 98.8% people don't know all of them!
A thread 🧵👇️
1️⃣ Get Value of a browser Cookie
We can retrieve the value of a stored cookie by accessing with document.cookie.
2️⃣ Convert RGB to Hex
Ever wondered how to convert a RGB color to hex in JavaScript. Worry no more!
3️⃣ Check if array is empty
This simple one liner to check if an array is empty, will return true or false as result.
4️⃣ Find the day of year
Snippet to help you find which is the day by a given date.
5️⃣ Find the number of days between two days
Find the days between 2 given days using the following snippet.
6️⃣ Clear All Browser Cookies
You can easily clear all cookies stored in a web page by accessing the cookie using document.cookie and clearing it.
7️⃣ Get Query Params from URL
You can easily retrieve query params from a url either by passing window.location or the raw URL.
8️⃣ Log Time from Date
We can log time, in the format hour::minutes::seconds from a given date
9️⃣ Check if a number is even or odd
% operator makes it super easy to check if a given number is odd or even.
🔟 Get User Selected Text
One line snippet to grab the text that is currently selected by a user.
See Part 1 for 10 more Fantastic JavaScript Snippets 🔥👇️
If you found this thread helpful, please consider following me @saviomartin7 and retweeting the first tweet.
Thank you so much for your support, friends! 🙏
Share this Scrolly Tale with your friends.
A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.