55

How to add region to collapse and expand code in java script. If any body knows solution, it will be great. thanks in advance.

Sharad
  • 1,192
  • 1
  • 8
  • 20
  • 2
    Possible duplicate of [how to implement regions/code collapse in javascript](https://stackoverflow.com/questions/1921628/how-to-implement-regions-code-collapse-in-javascript) – Andrei Dragotoniu Oct 13 '17 at 08:24
  • Regions are usually editor dependent, not a language feature. Some developers argue that the concept of regions are inherently bad, since they promote hiding ugly code, when you ought to just structure your code properly so regions aren't necessary. – Nikolaj Dam Larsen Oct 13 '17 at 08:28

3 Answers3

98

It depends only on the IDE.

vscode, for example, added support for code regions in september 2017

https://code.visualstudio.com/updates/v1_17#_folding-regions

For javascript:

//#region

code

//#endregion

or

//region

and

//endregion

The same syntax could work also in different IDEs.

Michele Federici
  • 1,755
  • 1
  • 14
  • 17
35

This works great on Visual Studio 2017 ( I haven't tried with other versions)

Java Script Regions

enter image description here

JavaScriptRegions

Screen shot for outlining

enter image description here

curiousBoy
  • 6,334
  • 5
  • 48
  • 56
4

for older version(vs2015 and below) select your code block => press CTRL + M+H The Code Will be collapsible

Eid Sky
  • 49
  • 6