Developer Documentation
JavaScript
Updated September 19, 2026

Generate and Work with GUIDs in JavaScript

Generate, parse, format, and validate GUID/UUID values in JavaScript.

A GUID is Microsoft terminology for a 128-bit globally unique identifier. In practice, the canonical textual form is compatible with UUID formatting, although platform APIs may expose additional GUID-specific formats.

Quick Start#

The following example uses the standard JavaScript API or a widely used package for this task.

Quick start#

JavaScript
1const id = crypto.randomUUID();2console.log(id);3// Example: "d2719d7e-4050-4b1c-a7e0-4dbd1b7c8705"

Common Operations#

This second pattern covers a common production operation or a safer way to handle real input.

Validate canonical text#

JavaScript
1const GUID_RE = /^[--f]{}-[--f]{}-[-][--f]{}-[][--f]{}-[--f]{}$/i;23function isGuid(value) {4  return typeof value === "string" && GUID_RE.test(value);5}67console.log(isGuid(crypto.randomUUID()));

Important Notes#

The browser API returns the canonical UUID string. If you need .NET-specific brace or compact formats, format the string explicitly at your boundary.

Best Practices#

  1. Treat external input as untrusted and handle parse/validation errors explicitly.
  2. Keep encoding, units, formats, and library-specific mapping rules explicit at system boundaries.
  3. Add test vectors that cover empty input, Unicode text, malformed input, and representative production data.

References#

Implement GUID in other languages: