DEV Community

Cover image for 30 Killer JavaScript One-Liners That’ll Make You Look Like a Pro 😎

30 Killer JavaScript One-Liners That’ll Make You Look Like a Pro 😎

TAQUI ⭐ on October 29, 2023

TL;DR JavaScript has some really cool abilities that allow you to do amazing things with just a single line of code. Here are 30 useful ...
Collapse
 
frankwisniewski profile image
Frank Wisniewski •

If you put several commands in one line, separated by semicolons, it is not a one-liner

Collapse
 
moopet profile image
Ben Sinclair •

I ran uglify on my codebase and now my entire app is apparently a one-liner!

Collapse
 
best_codes profile image
BestCodes •

IKR xD

Collapse
 
best_codes profile image
BestCodes •

Couldn't agree with you more.

Collapse
 
webjose profile image
José Pablo Ramírez Vargas •

LOL! #1 a one-liner?? Bro, get serious.

Collapse
 
best_codes profile image
BestCodes •

IT is AI written, that's the problem. I agree with you though.

Collapse
 
crespire profile image
crespire • • Edited

I would probably not generate UUIDs this way. Use a library. While I am not an expert in this area, I am pretty sure a bit more goes into a UUID than what you've shown.

Just look at the source for the UUID package on NPM, it is not as simple as random characters: github.com/uuidjs/uuid/tree/main/src

Collapse
 
vladern profile image
vladyslav kuchmenko •

There is a better way with crypto.randomUUID() it has good support in modern browsers developer.mozilla.org/en-US/docs/W...

Collapse
 
crespire profile image
crespire •

Yes, the UUID library wraps this where it is available.

Collapse
 
dannickbedard profile image
Dannick Bedard •

Uuid should be unique. This math random has a small chance of generating the same output more than one. :D

Collapse
 
best_codes profile image
BestCodes •

The codes are AI written. Still cool though. The "Sure! .... " gives it away.

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
best_codes profile image
BestCodes •

Um, what does that mean? I don't understand what you are saying…

Collapse
 
best_codes profile image
BestCodes •

And I don't know if "alert("Hello, world!"); is all that killer. That was the first JS code I ever ran I think.

Collapse
 
vladern profile image
vladyslav kuchmenko •
  1. To generate a random UUID I recommend using crypto.randomUUID() method it has pretty good support for modern browsers: developer.mozilla.org/en-US/docs/W...
Collapse
 
best_codes profile image
BestCodes •

Why would someone do that? :D

Some comments have been hidden by the post's author - find out more