Skip to content

Instantly share code, notes, and snippets.

@RookieOne
Last active August 29, 2015 14:11
Show Gist options
  • Save RookieOne/aec83b2d382da13a2e62 to your computer and use it in GitHub Desktop.
Save RookieOne/aec83b2d382da13a2e62 to your computer and use it in GitHub Desktop.
JB's JavaScript coding standards
// File Names
// lowercase separated by dashes
// not underscores because Node uses dashes for require()
// so using dashes for file names keeps with that standard
// lowercase because not all OS have case sensitive file names
// RIGHT
application.js
some-cool-controller.js
// WRONG
Application.js
someCoolController.js
some_cool_controller.js
// Quotes
// Use double quotes over single quotes.
// Performance reasoning for single quotes is silly.
// Double quotes match other languages more.
// HTML & JSON prefer double quotes. Following Twitter Bootstrap example.
// RIGHT
"Hello World"
// WRONG
'Hello World'
// Declaring variables
// https://github.com/felixge/node-style-guide
// I concur with these points from the above link:
// Declare one variable per var statement, it makes it easier to re-order the lines.
// Ignore Crockford when it comes to declaring variables deeper inside a function,
// just put the declarations wherever they make sense.
// RIGHT
var keys = ['foo', 'bar'];
var values = [23, 42];
var object = {};
while (keys.length) {
var key = keys.pop();
object[key] = values.pop();
}
// WRONG
var keys = ['foo', 'bar'],
values = [23, 42],
object = {},
key;
while (keys.length) {
key = keys.pop();
object[key] = values.pop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment