Place Opening Braces in a New Line for a JavaScript function – Visual Studio 2010

Developers have different way of indenting JavaScript code in Visual Studio 2010. When it comes to methods, some of them keep the opening braces in the same line of the method declaration like this:

<script type="text/javascript">
function
someFun() {
}
</script>

This is also the default indentation in Visual Studio 2010. If you want to change that and place opening braces in a new line, then Go to Tools > Options > Text Editor > JScript > Formatting > Check the box ‘Place open brace on new line for functions’

image

Now when you type the same function and hit enter before the last braces, Visual Studio indents the opening braces on a new line as shown below

<script type="text/javascript">
function
someFun()
{
}
</script>






About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.

2 comments:

Anonymous said...

Good. Thanks for sharing.

Anonymous said...

Thanks for the tip. I like my javascript open braces to be consistent with my c# code.