JavaScript Coding Standard
If a topic is not covered in this document, refer to airbnb JavaScript Style Guide
// bad var feedbackresponserecipient = ‘responserecipient’; // badAsWell var feedbackResponseRecipient = ‘responserecipient’; // b_a_d var feedback_response_recipient = ‘responserecipient’; // G_O_O_D var FEEDBACK_RESPONSE_RECIPIENT = ‘responserecipient’; |
When wrapping lines, the main objective is to improve readability. Feel free to break rules if it improves readability. Do not accept the auto-formatting suggested by the IDE as Eclipse’s JavaScript auto-formatting is very different from that suggested by TEAMMATES. It is OK to exceed the limit slightly or wrap the lines much shorter than limit. In general,
// Bad
// Good arg3, arg4);
// Bad d; ‘split into two parts’; $('#responses'). // Good mySum = a + b + c + d; + ‘split into two parts’;
// Bad - longName5) + 4 * longName6; // Good longName1 = longName2 * (longName3 + longName4 - longName5) + 4 * longName6;
// Bad alpha = (aLongBooleanExpression) ? beta : gamma; : gamma; alpha = (aLongBooleanExpression) ? beta : gamma; // Good alpha = (aLongBooleanExpression) ? beta : gamma; : gamma; alpha = (aLongBooleanExpression) ? beta : gamma; |
Additional Reading