Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP W3.CSS C C++ C# HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST TOOLS

JS Tutorial

JS Home JS Introduction JS Where To JS Output JS Syntax JS Operators JS If Conditions JS Loops JS Strings JS Numbers JS Functions JS Timers JS Objects JS Scope JS Dates JS Temporal  New JS Arrays JS Sets JS Maps JS Iterations JS Math JS RegExp JS Data Types JS JSON JS Errors JS Debugging JS Style Guide JS Reference JS Projects  New JS Versions JS HTML DOM JS HTML Events JS HTML First

JS Advanced

JS Functions JS Objects JS Classes JS Asynchronous JS Modules JS Meta & Proxy JS Typed Arrays JS DOM Navigation JS Browser API JS Web API JS Graphics

Old Technologies

JS AJAX JS jQuery

JS Examples

JS Examples

ECMAScript 2027

Anticipated Features to ES2027

  • Temporal API
    The long-time-overdue successor to the buggy, 30-year-old Date object. Unlike Date, Temporal objects are immutable and provide first-class support for time zones and non-Gregorian calendars.

  • Explicit Resource Management (using keyword)
    C#-style block-scoped disposal variables that auto-clean up database connections and streams when leaving context, avoiding try...finally boilerplate.

Resource Management with using

JavaScript 2026 added two keywords to automatically manage and dispose resources (like file handles or database connections) when they go out of scope, reducing the need for explicit try...finally blocks.

  • using provides synchronous cleanup of block-scoped variables.
  • await using provides asynchronous cleanup for resources like network streams.


Explicit Resource Management

The using Keyword

The using keyword is an addition to JavaScript 2026. It provides a mechanism for managing resources that require explicit disposal.

It declares a block-scoped variable, similar to const, but with the difference that it guarantees synchronous disposal of the used resource when the variable goes out of scope.

Example

class MyResource {
  constructor(name) {
    this.name = name;
    myDisplay(`Resource ${this.name} acquired.`);
  }
  [Symbol.dispose]() {
    myDisplay(`Resource ${this.name} disposed.`);
  }
}

function manageResource() {
using resource = new MyResource("Database Connection");

// Use the resource here
myDisplay(`Using resource: ${resource.name}`);
}
Try it Yourself »

The using keyword simplifies resource management by automatically handling the cleanup process, reducing the risk of resource leaks and improving code readability compared to manual try...finally blocks for disposal.

  • Resource Management
    using is designed for objects that implement the Symbol.dispose method, which defines the cleanup logic for the resource.

  • Synchronous Disposal
    When a variable declared with using exits its scope (at the end of a block or function), its Symbol.dispose method is automatically called.

  • Asynchronous Disposal
    For resources requiring asynchronous cleanup, the await using declaration can be employed. This ensures that the disposal process is awaited before the variable fully goes out of scope.

  • Block-Scoped
    Like const, variables declared with using are local to the block in which they are declared, and must be initialized at the time of declaration.

  • Immutable
    Like to const, variables declared with using cannot be reassigned after initialization.

Browser Support

using is already supported in many browsers:

Chrome
134
Edge
134
Firefox
141
Safari
Opera
119
Mar 2025 Mar 2025 Jul 2025 May 2025

Explicit Resource Management

await using

Inspired by other languages, JavaScript 2026 introduces using blocks for automatic cleanup of resources like file handles, database connections, or network streams.

This is especially beneficial for asynchronous operations:

Example

async function processFile() {
  using fileHandle = await openFile('data.txt');

// Work with fileHandle here

} // fileHandle is automatically closed here
Try it Yourself »

Browser Support

await using is already supported in many browsers:

Chrome
134
Edge
134
Firefox
141
Safari
Opera
119
Mar 2025 Mar 2025 Jul 2025 May 2025


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

-->