coderef

withLimited availability

The with JavaScript statement adds a given object to the chain of scopes used to evaluate names.

Not yet supported in all major browsers — check the table and provide a fallback.

Discouraged: JavaScript strict mode prohibits the with statement. Use instead: Destructuring

Browser support

DesktopChrome
1–37Not supported
38+Supportedsince Oct 7, 2014
Current: 155
Edge
12+Supportedsince Jul 29, 2015
Current: 154
Firefox
1–47Not supported
48+Supportedsince Aug 2, 2016
Current: 157
Safari
1–9.1Not supported
10+Supportedsince Sep 20, 2016
Current: 27
MobileChrome Android
18–37Not supported
38+Supportedsince Oct 8, 2014
Current: 155
Firefox Android
4–47Not supported
48+Supportedsince Aug 2, 2016
Current: 157
Safari iOS
1–9.3Not supported
10+Supportedsince Sep 13, 2016
Current: 27

How to use

Support is still inconsistent across browsers. Use feature detection and test carefully.

Example

Full syntax and examples are on MDN: Symbol.unscopables.

Feature detection

JS · check before using
// Syntax can't be tested with an if-statement — an unsupported
// browser fails to parse the whole script. Either transpile for older
// targets (e.g. Babel/TypeScript/esbuild), or probe in isolation:
let supported = true;
try {
  new Function("/* code that uses the syntax */");
} catch {
  supported = false;
}

This is a language syntax feature.

Sub-features

Support for each part of the feature (3). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
Array.@@unscopables38124810384810
Symbol.unscopables381248938489
with112111841