JavaScript curly braces with no function or json

The only logical reason to do something like this, in my mind, is as an organizational technique.

function banana(){
    // private members
    {
        var foo = "foo",
            bar = "bar",
            baz = "baz";

        function bux(){
            console.log("bux");
        }
    }

    // public members

    this.fin = "fin";
    this.fang = "fang";
    this.foom = "foom";

    this.shamalamadingdong = function(){
        bux();
    };
}

Also, most IDEs will allow you to collapse that "private members" block and get it out of your way.


It's a block and completely pointless unless you label it:

block: {
    var s_account="blog";
    console.log("executed");
    break block;
    console.log("not executed");
}

Tags:

Javascript