| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Statements/block | [Back] [Original] |
Get to know MDN better
This feature is well established and works across many devices and browser versions. Its been available across browsers since 20157.
{ }
| Implemented in | JavaScript 1.0 |
| ECMAScript edition | ECMA-262 1st edition |
{
_1
_2
...
_n
}
ifforwhile
varvar Execution Context
var x = 1;
{
var x = 2;
}
alert(x); // outputs 2
2 var
let constletconst
let x = 1;
{
let x = 2;
}
console.log(x); // logs 1
function function function Execution Context function var function
function foo() {
{
var a = "var";
{
let a = "let";
console.log(a); // let
}
}
console.log(a); // var
}
foo();
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-block |
This page was last modified on 2025716 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 |