Every reach for a library for UUID v4 ends here: the runtime has shipped the function for years, and it is the honest base for ids generated in the browser.

const id = crypto.randomUUID();
// 3b241101-e2bb-4255-8caf-4136c566a962
  • The call demands a secure context, https or localhost; an insecure page gets a TypeError, which turns a silent misuse into a loud development-time error.
  • v4 means random bits, not a counter: fine for request ids, draft rows, and client-side dedup, wrong for anything that must sort by creation order.
  • It is a uniqueness guarantee, not a secrecy guarantee; secrets and tokens come from different parts of the crypto object, and the two roles live in separate rooms.

Where it fits

Optimistic interfaces are the classic home: create the record client-side with a real id, show it immediately, and reconcile when the server answers. The id survives a refresh only if you persist it, which is the one caveat the trick needs.

gacor the way tools are when they delete work: the dependency entry, the bundle line, and the import all vanish at once. Keep a human-readable slug for anything a person reads, and let the UUID stay opaque.