How to Implement Block scope in JavaScript

How to Implement Block scope in JavaScript

In this article, you will learn How to Implement Block scope in JavaScript. Block scope is a new ES6 feature. We create a new block scope

In this article, you will learn How to Implement Block scope in JavaScript.

Block scope is a new ES6 feature. You create a new block scope for each set of curly braces. you use let and const keywords to add Variables to block scope.

Implement Block scope in JavaScript

Consider the example below:

function bScope() {

    console.log('Scope at top');

    let scopeExample = 8;

    console.log(scopeExample);

    {

        console.log('Scope 2 value');

        let scopeExample = 'scope 2 value 2 ';

        console.log(scopeExample);

    }

    {

        console.log('Scope 3');

        let scopeExample = ' scope 3 value';

        console.log(scopeExample);

    }

}

bScope();

code examples javascript

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

4 Ways You Can Get Rid of Dirty Side Effects for Cleaner Code in JavaScript

4 Ways You Can Get Rid of Dirty Side Effects for Cleaner Code in JavaScript. Bugs are born in many ways. Creating side effects is one of them. Some people say side effects are evil, some say they’re not.

Static Code Analysis: What It Is? How to Use It?

Static code analysis is a method of debugging by examining source code before a program is run. It's done by analyzing a set of code against a set (or multiple sets) of coding rules. Static code analysis and static analysis are often used interchangeably, along with source code analysis.

What is JavaScript - Stackfindover - Blog

What is PHP: - Who invented PHP, how it works, answers to all such questions about PHP, and much other information, you are going to

50+ Basic Python Code Examples

In this tutorial, we'll learn 50+ Basic Python Code Examples.List, strings, score calculation and more..

Who Else Wants to Write Clean JavaScript Code?

Who Else Wants to Write Clean JavaScript Code? 7 Tips to Make Your Coworkers Fall in Love With Your Code.