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
Best Codes

IKR xD

Collapse
 
best_codes profile image
Best Codes

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
Best Codes

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
 
manchicken profile image
Mike Stemle

It’s frustrating to see so many articles listing stuff without adding any value. You don’t cover how these work for folks, and I’m not sure memorizing a list of snippets is as helpful.

Collapse
 
best_codes profile image
Best Codes

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
Best Codes

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

Collapse
 
best_codes profile image
Best Codes

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
 
syeo66 profile image
Red Ochsenbein (he/him)

Uh. Did not like my comment? How about challenging it and starting to discuss?

Collapse
 
best_codes profile image
Best Codes

Why would someone do that? :D

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
 
syeo66 profile image
Info Comment hidden by post author - thread only accessible via permalink
Red Ochsenbein (he/him) • Edited

"...That’ll Make You Look Like a Pro" I'm afraid the contrary is true. If someone in my team would come up with some of those, I'd have them think hard about what it means to be a pro within a team...

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