How to Create a UUID in JavaScript

The UUID identifier has been used in programming since the days a baby-faced David Walsh became a professional software engineer. My first exposure to UUIDs was via a ColdFusion app I inherited and … the less we say about that the better. In any event, I was recently surprised to see that JavaScript has the […]

The post How to Create a UUID in JavaScript appeared first on David Walsh Blog.


This content originally appeared on David Walsh Blog and was authored by David Walsh

The UUID identifier has been used in programming since the days a baby-faced David Walsh became a professional software engineer. My first exposure to UUIDs was via a ColdFusion app I inherited and … the less we say about that the better. In any event, I was recently surprised to see that JavaScript has the ability to create UUIDs.

Developers can use the native JavaScript crypto library to generate a UUID:

crypto.randomUUID() // '5872aded-d613-410e-841f-a681a6aa8d8b'
crypto.randomUUID() // 'fe6c7438-a833-4c7c-9ea3-cdc84ef41dfc'
crypto.randomUUID() // 'e47a03d4-5da3-4451-a2c1-265de99cc2c1'
crypto.randomUUID() // '04cdadeb-0228-43db-85dc-ce7e960a6cde'

It’s important to remember that the UUID is not guaranteed to be unique, though the probability of repetition is incredibly low. I look forward to exploring the window.crypto API further to see what other cool things we can do!

The post How to Create a UUID in JavaScript appeared first on David Walsh Blog.


This content originally appeared on David Walsh Blog and was authored by David Walsh


Print Share Comment Cite Upload Translate Updates
APA

David Walsh | Sciencx (2021-09-30T01:47:39+00:00) How to Create a UUID in JavaScript. Retrieved from https://www.scien.cx/2021/09/30/how-to-create-a-uuid-in-javascript/

MLA
" » How to Create a UUID in JavaScript." David Walsh | Sciencx - Thursday September 30, 2021, https://www.scien.cx/2021/09/30/how-to-create-a-uuid-in-javascript/
HARVARD
David Walsh | Sciencx Thursday September 30, 2021 » How to Create a UUID in JavaScript., viewed ,<https://www.scien.cx/2021/09/30/how-to-create-a-uuid-in-javascript/>
VANCOUVER
David Walsh | Sciencx - » How to Create a UUID in JavaScript. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/30/how-to-create-a-uuid-in-javascript/
CHICAGO
" » How to Create a UUID in JavaScript." David Walsh | Sciencx - Accessed . https://www.scien.cx/2021/09/30/how-to-create-a-uuid-in-javascript/
IEEE
" » How to Create a UUID in JavaScript." David Walsh | Sciencx [Online]. Available: https://www.scien.cx/2021/09/30/how-to-create-a-uuid-in-javascript/. [Accessed: ]
rf:citation
» How to Create a UUID in JavaScript | David Walsh | Sciencx | https://www.scien.cx/2021/09/30/how-to-create-a-uuid-in-javascript/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.