r/javascript • u/smellycode • Mar 02 '19
Useful javascript one-liners.
https://medium.com/@smellycode/js-one-liners-8bc0a6af2345?source=friends_link&sk=a9295a05aef9e514e137fca7eeb89cd1
344
Upvotes
r/javascript • u/smellycode • Mar 02 '19
6
u/[deleted] Mar 02 '19 edited Mar 02 '19
The last one fails when the random number is smaller than 0x100000. You need to add
.padStart(6, '0')at the end to make sure it's 6 characters.I've also used
Math.random().toString(16).slice(-6)to generate random hex colors. There is a very low chance of getting not enough characters and the distribution is pretty uniform, but still not completely safe.