5let constants;
6
7async function language(data: string) {
8 { 9 if (data === "en") {10 console.log("en", data);11 constants = en.translations;12 } else if (data === "fr") {13 console.log("fr", data);14 constants = fr.translations;15 }16 }17}
18
19export { language, constants, locale };
In JavaScript, prior to ES6, standalone code blocks delimited by curly braces do not create a new scope and have no use.
For example, these curly braces do nothing to foo
:
{
var foo = bar();
}
In ES6, code blocks may create a new scope if a block-level binding (let
and const
), a class declaration or a function declaration (in strict mode) are present. A block is not considered redundant in these cases.
{}
if (foo) {
bar();
{
baz();
}
}
function bar() {
{
baz();
}
}
{
function foo() {}
}
{
aLabel: {
}
}
while (foo) {
bar();
}
if (foo) {
if (bar) {
baz();
}
}
function bar() {
baz();
}
{
let x = 1;
}
{
const y = 1;
}
{
class Foo {}
}
aLabel: {}