javascript coding style
Update: I don’t follow this style anymore. I use semistandard
This is the javascript coding style I follow
- Comma first
- Two space indentation
- No semicolon
- Use single quotes
For example
var express = require('express')
, User = mongoose.model('User')
, auth = require('./authorization')
, arr = [1, 2, 3, 4]
User
.findOne({ name: 'abc' })
.run(function (err, user) {
if (err) return res.send(400)
if (!user) {
// do something
return res.send(403)
}
res.json(user)
})
Other styling guides out there:
- npm coding style
- Google javascript styling guide
- Github javascript styling guide
- idiomatic.js
- Felix’s node.js style guide
When I am developing on the server side (node.js) I don’t use semicolons, otherwise on the client side I mostly do.