Search code examples
javascriptjquerycode-regions

Is it OK to put javascript/jquery code in multiple-level curly braces?


My intention is to create C#-like custom code region for my jquery/js scripts.

I just don't know if it is OK or may create any un-awareness bug later on?

E.g.

{ //region Some Region Description
  console.log('Some js code');

  { //region Inner Region Description
    $('someSelector').html('Some elements');
  } //endregion

} //endregion

Solution

  • What you are creating are statement blocks. Prior to ES6 I can't think of any side effects of doing that, but using intrinsic language features for semantics like that is pretty ugly.

    ES6 introduces block scoped syntax e.g. let and const statements so what you suggest could make things confusing.