Everyone has their own style when coding. For some people, the style they use might be so inconsistent that it looks like they used a program to randomize the code layout so it would confuse everyone as much as possible. In general it’s best to use a consistent coding style, for your own sake, and for the sake of everyone else who might look at your code. To keep things consistent you can use a style guide, which will help you remember and use your rules.
There are style guides all over the internet, and even plenty that aren’t shown publicly that are used inside companies to control the consistency of code between their employees. Google, jQuery, Dojo, Douglas Crockford, and many others have come up with their own style guides and they’re each slightly different in their own ways. Each guide is great in its own right, but you might never find one that is right for you.
Part of the reason there are so many style guides out there is because every person is different and has their own preferences. I’ve seen this a lot in programming, even between myself and my twin brother. If two people should have identical coding styles, it should be identical twins right? The point of coding style guides is consistency, which allows people to be able to read your code more quickly and easily. Usually, most coding styles are pretty similar so that even if people didn’t share the same guidelines, it would be simple enough to read.
If you’re working in a large group of people, try to get everyone to adopt the same set of guidelines, but also realize these are guidelines and not rules. If your team has a particularly difficult time determining guidelines that will work for all of the members, you could go the way of the NPM style guide (though I personally wouldn’t recommend that particular guide), which is pretty minimal and offers a basic set of guidelines rather than a comprehensive set. Guides can be strayed away from for the sake of individual circumstances that would actually be more readable if they’re done a different way, though I would consult with your team members to decide the best course of action.
Personally I don’t currently use a well-defined style guide, which, I’m sure, is the case for many people. Part of the reasoning behind this is that as I mature in my programming, I see more and more styles and change the style of my programming based on those experiences, but overall I’ve had a pretty consistent style. I’ve always preferred 4-space tabs, semi-liberal spacing (though not as liberal as many other programmers), and other such commonplace things.