<commit_before>## Scopes and namespaces

Although JavaScript deals fine with the syntax of two matching curly
braces for blocks, it does **not** support block scope; hence, all that is left 
is in the language is *function scope*.

    function test() { // a scope
        for(var i = 0; i < 10; i++) { // not a scope
            // count
        }
        console.log(i); // 10
    }

> **Note:** When not used in an assignment, return statement or as a function 
> argument, the `{...}` notation will get interpreted as a block statement and 
> **not** as an object literal. This, in conjunction with 
> [automatic insertion of semicolons](#semicolon), can lead to subtle errors.

There are also no distinct namespaces in JavaScript. This means that everything 
gets defined in **one** globally shared namespace.

Each time a variable is referenced, JavaScript will traverse upwards through all 
the scopes until it finds it. In the case that it reaches the global scope and 
still has not found the requested name, it will raise a `ReferenceError`.

### The bane of global variables

    // script A
    foo = '42';

    // script B
    var foo = '42'

The above two scripts do **not** have the same effect. Script A defines a 
variable called `foo` in the *global* scope and script B defines a `foo` in the
*local* scope.

Again, that is **not** at all the same effect, not using `var` can have major 
implications.

    // global scope
    var foo = 42;
    function test() {
        // local scope
        foo = 21;
    }
    test();
    foo; // 21

Leaving out the `var` statement inside the function `test` will override the 
value of `foo`. While this might not seem like a big deal at first, having 
thousands of lines of JavaScript and not using `var` will introduce hard to 
track down bugs.
    
    // global scope
    var items = [/* some list */];
    for(var i = 0; i < 10; i++) {
        subLoop();
    }

    function subLoop() {
        // scope of subLoop<commit_msg>Minimal change in wording<commit_after>## Scopes and namespaces

Although JavaScript deals fine with the syntax of two matching curly
braces for blocks, it does **not** support block scope; hence, all that is left 
is in the language is *function scope*.

    function test() { // a scope
        for(var i = 0; i < 10; i++) { // not a scope
            // count
        }
        console.log(i); // 10
    }

> **Note:** When not used in an assignment, return statement or as a function 
> argument, the `{...}` notation will get interpreted as a block statement and 
> **not** as an object literal. This, in conjunction with 
> [automatic insertion of semicolons](#semicolon), can lead to subtle errors.

There are also no distinct namespaces in JavaScript. This means that everything 
gets defined in **one** globally shared namespace.

Each time a variable is referenced, JavaScript will traverse upwards through all 
the scopes until it finds it. In the case that it reaches the global scope and 
still has not found the requested name, it will raise a `ReferenceError`.

### The bane of global variables

    // script A
    foo = '42';

    // script B
    var foo = '42'

The above two scripts do **not** have the same effect. Script A defines a 
variable called `foo` in the *global* scope and script B defines a `foo` in the
*current* scope.

Again, that is **not** at all the same effect, not using `var` can have major 
implications.

    // global scope
    var foo = 42;
    function test() {
        // local scope
        foo = 21;
    }
    test();
    foo; // 21

Leaving out the `var` statement inside the function `test` will override the 
value of `foo`. While this might not seem like a big deal at first, having 
thousands of lines of JavaScript and not using `var` will introduce hard to 
track down bugs.
    
    // global scope
    var items = [/* some list */];
    for(var i = 0; i < 10; i++) {
        subLoop();
    }

    function subLoop() {
        // scope of subLoop
{'fraction_non_alphanumeric': 0.08922305764411027, 'fraction_numerical': 0.009022556390977444, 'mean_word_length': 2.7439024390243905, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1592158', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1076, 'n_words': 580}