
"Writing JavaScript that opens something (a file, a stream, a lock, a database connection) also means remembering to clean it up. And if we're being honest, that cleanup doesn't always happen. I know I've missed it more than once. JavaScript has always made this our problem. We reach for try / finally, tell ourselves we'll be careful, and hope we didn't miss an edge case. It usually works, but it's noisy and easy to get subtly wrong."
"using: cleanup, but make it the runtime's job At a high level, using declares a resource that will be automatically cleaned up when it goes out of scope. Conceptually: using file = await openFile("data.txt"); // do something with file // file is automatically closed at the end of this scope No try. No finally. No "did I remember to close""
Opening files, streams, locks, or database connections requires explicit cleanup and forgetting to close resources remains common. try/finally is verbose, repetitive, and easy to get subtly wrong, especially as the number of resources grows and ordering or error paths matter. Explicit resource management introduces a language-level using construct that declares resources and ensures the runtime automatically cleans them up at scope exit. Using eliminates boilerplate try/finally, reduces mental overhead, and shifts cleanup responsibility to the runtime, simplifying code and lowering the risk of subtle resource-leak bugs.
Read at Allthingssmitty
Unable to calculate read time
Collection
[
|
...
]