Example 1 — Example
Core usage.
JavaScript
"use strict";
try {
// with ({ a: 1 }) { console.log(a); } // SyntaxError in strict mode
console.log("avoid with — use const obj = ...; obj.prop");
} catch (e) {
console.log(e.name);
}How It Works
- Legacy. with is banned in strict mode.
- Prefer. Explicit object references.
