JSFiddle - React, Tailwind, and code Playground

JavaScript

function example() {
    let x = 10;
    const z = 30;
    if (true) {
        let y = 20; // y 仅在块作用域内有效
        console.log(y); // 20
    }
    console.log(x); // 10
    console.log(z); // 30
    // console.log(y); // ReferenceError: y is not defined
}

example();