re: Who was that masked variable? VIEW POST

FULL DISCUSSION
 

My first thought was, wouldn't it be cool to have a formula that stays the same but you could mask some of the variables with new values before running it! But if that masking happens conditionally in an if statement, then the variable will just revert back to their original values when the execution leaves the if and we're right back to where we started.

BTW, the above code works with const too!

{
    const i = 3;
    {
        const i = 29;  // <-- This is a new variable and masks the original
        console.log(i);  // <-- Will print 29
    }
    console.log(i); // <-- Back to the original variable, will print 3
}
code of conduct - report abuse