Proper JavaScript line breaking? -
is breaking long boolean expression this
var x = === b && c === d && e === f;
to more readable
var x = === b && c === d && e === f;
considered bad practice? long variable names former can become extremely long.
you free put line breaks in expression this. not considered bad practice. in fact, it's practice keep code readable without lots of horizontal scrolling if line breaks required in order that, recommended.
many corporate coding style guides specify max code line length easy reading , line breaks required in order follow types of guidelines.
check out douglas crockford's javascript conventions or google's style guide select quote each:
when possible, function arguments should listed on same line. if doing exceed 80-column limit, arguments must line-wrapped in readable way. save space, may wrap close 80 possible, or put each argument on own line enhance readability. indentation may either 4 spaces, or aligned parenthesis.
crockford's code conventions javascript programming language
avoid excessively long lines. when statement not fit nicely on single line, may necessary break it. best break after { left brace, [ left bracket, ( left paren, , comma, or before . period, ? question mark, or : colon. if such break not feasible, break after operator , continue on next line 8 spaces added current indentation. 8 spaces not change current indentation.
line length
80 characters or less (for laptop side-by-side diffing , two-window tiling
Comments
Post a Comment