r/learnjavascript • u/[deleted] • Jan 15 '25
45 Powerful JavaScript One-Liners That You Must Know
JavaScript is known for its flexibility and concise syntax. One of the best ways to write more efficient and elegant code is by using one-liners. These short, compact snippets can often replace longer, more complex code. Whether you're a beginner or a seasoned developer, mastering JavaScript one-liners can improve your coding efficiency and help you write cleaner code
🔗 Read More Here: 👇👇👇
https://calicodex.com/45-powerful-javascript-one-liners-you-must-know/
0
u/TheRNGuy Jan 16 '25
I know the most useful in Greasemonkey scripts:
const $ = (thing) => document.querySelector(thing)
const $$ = (thing) => [...document.querySelectorAll(thing)](reason for [... ] is to convert NodeList to Array, because NodeList doesn't have some methods)
14. Convert a Number to a String
You can also do 1 + ""
5
u/syntheticcdo Jan 15 '25
well, 44 because 21 and 6 are the same thing :)