bhylu.com

Advertisements

JS Code Blocks

Braces can group statements into a block. Let and const declarations stay inside that block.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

A practical example

JavaScript

const name = "Outside";
{
  const name = "Inside";
  console.log(name);
}
console.log(name);

What happens

Inside is printed first, then Outside.