JavaScript now supports explicit resource management through the `using` keyword and disposal symbols (`Symbol.dispose`, `Symbol.asyncDispose`). This language-level feature automatically cleans up resources like files, streams, locks, and database connections when they go out of scope, eliminating the need for verbose `try/finally` blocks. Resources are disposed in reverse order of declaration, similar to a stack. For more complex scenarios, `DisposableStack` and `AsyncDisposableStack` provide programmatic control. The feature is available in Chrome 123+, Firefox 119+, and Node.js 20.9+, with Safari support pending.

5m read timeFrom allthingssmitty.com
Post cover image
Table of contents
We’re bad at cleanup (and the language doesn’t help)using : cleanup, but make it the runtime’s jobHow cleanup actually worksWhen you need await usingStacking resources without the headacheScope is the pointWhen using isn’t enoughThis isn’t just a back-end featureWhat’s the catch?A better default for cleanup

Sort: