| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Statements/with | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
Avoid using this feature in new projects.
JavaScript strict mode prohibits the with statement.
This feature may be a candidate for removal from web standards or browsers.
Consider using the following features instead: Destructuring.
with .
with (expression)
statement
expression. .
statement. '' ' ' . .
foo; //
foo.bar; // bar
. .
const foo = { bar: 1 };
console.log(foo.bar);
// foo .
// bar foo .
console.log(globalThis.Math === Math); // true
with . (in ) .
with this .
with ([1, 2, 3]) {
console.log(toString()); // 1,2,3
}
@@unscopables , ( ) . Symbol.unscopables .
with . with .
: with . with . , .
: with JavaScript , . .
function f(x, o) {
with (o) {
console.log(x);
}
}
f with x . x o.x f f . x . . .
: with . . .
function f(foo, values) {
with (foo) {
console.log(values);
}
}
ECMAScript 5 f([1, 2, 3], obj) , with values obj . ECMAScript 2015 Array.prototype values ( values ). with values [1, 2, 3].values , .
values Array.prototype[@@unscopables] values values . values , .
with Math . with PI cos sin . JavaScript Math .
let a, x, y;
const r = 10;
with (Math) {
a = PI * r * r;
x = r * cos(PI);
y = r * sin(PI / 2);
}
let a, x, y;
const r = 10;
{
const { PI, cos, sin } = Math;
a = PI * r * r;
x = r * cos(PI);
y = r * sin(PI / 2);
}
IIFE .
const objectHavingAnEspeciallyLengthyName = { foo: true, bar: false };
if (((o) => o.foo && !o.bar)(objectHavingAnEspeciallyLengthyName)) {
// .
}
const namespace = new Proxy(
{},
{
has(target, key) {
// `console` .
if (key in globalThis) {
return false;
}
// .
return true;
},
get(target, key) {
return key;
},
},
);
with (namespace) {
console.log(a, b, c); // "a" "b" "c"
}
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-with-statement |
This page was last modified on 2026 7 15 by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |