Common JavaScript Snippets

These are the most  common JavaScript Snippets that I use. You can check out the utils.js script on my GitHub Gist.


Generate UUID

Universally Unique Identifier is a 128-bit integer that identifies data.

https://stackoverflow.com/a/8809472/6622966
https://stackoverflow.com/questions/1155008/how-unique-is-uuid

See the Pen Generate UUID by lim xing zhi (@limxz) on CodePen.


Local Storage Access

Local Storage is a Web API to store persistent data locally on the browser across sessions.

https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage

See the Pen Local Storage by lim xing zhi (@limxz) on CodePen.


Input Control - Throttle and Debounce

Throttle and Debounce functions are ways we can prevent a sudden flood of inputs by buffering the inputs handled.

https://css-tricks.com/debouncing-throttling-explained-examples/
https://www.30secondsofcode.org/js/s/throttle
https://www.30secondsofcode.org/js/s/debounce

https://gist.github.com/beaucharman/e46b8e4d03ef30480d7f4db5a78498ca
https://gist.github.com/beaucharman/1f93fdd7c72860736643d1ab274fee1a

See the Pen Throttle Debounce by lim xing zhi (@limxz) on CodePen.