Bun Basics
Let's explore the fundamental APIs that Bun provides. These are globally available and don't require any imports.
The Bun Global Object
Bun exposes a global Bun object with many useful properties and methods:
Loading Bun Playground...
High-Resolution Timing
Bun provides nanosecond-precision timing for performance measurement:
Loading Bun Playground...
Fast Hashing
Bun includes a fast hashing function for strings:
Loading Bun Playground...
HTML Escaping
Safely escape HTML to prevent XSS attacks:
Loading Bun Playground...
Deep Equality Checking
Compare objects deeply with Bun.deepEquals:
Loading Bun Playground...
Sleep Functions
Bun provides both async and sync sleep functions:
Loading Bun Playground...
Exercise: Timing Comparison
Measure how long it takes to perform different operations:
Loading Bun Exercise...
Exercise: Hash Comparison
Use Bun.hash to check if two strings are the same:
Loading Bun Exercise...

