Favorites

JavaScript with Statement

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee

The with statement is deprecated and is not allowed in strict mode. Use destructuring instead.

with
JavaScript OtherThis statement is supported by all modern browsers.
Deprecated Updated 28th November 2026

The deprecated with statement adds an object's properties to the scope of a block. It is forbidden in strict mode and shouldn't be used.

Description

The with statement extends the scope chain for a block, so the object's properties can be used like variables. It makes code ambiguous (is x a property or a variable?), slows down engines and is not allowed in strict mode, modules or classes. Use destructuring, const { a, b } = obj, to get short names for properties instead.

Inside a with block, JavaScript looks up each name first as a property of the object and only then in the surrounding scopes. That means adding a property to the object later can silently change which variable a piece of code refers to, which makes bugs very hard to find. It also prevents engines from optimizing the code, because names can't be resolved in advance.

Because modules and classes are always strict, with can't be used in modern code at all. Destructuring the properties you need into local variables, or simply keeping a short variable name for the object, gives the same convenience without the ambiguity.

Syntax

with (object) {
  statement
}

Example

// Avoid: with (point) { console.log(x + y); }
const point = { x: 2, y: 3 };
const { x, y } = point;
console.log(x + y);

Browser Support

The following information will show you the current browser support for the with statement. Hover over a browser icon to see the version that first introduced support for this statement.

This statement is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee