Javascript best practices for variables and functions

I've used several different languages and I was wondering what the "best practices" are for writing javascript variable and function names so that I don't annoy everyone I end up working with by using non-standard naming conventions.

If I'm writing a variable for last name, should I format it:

var last_name;
var lastName;

or some other way?

If I'm writing a function, how would I format it?



or is there a better way?

Are there any other naming/commenting standards I should know about?


  • there are some naming conventions that we use at our company, following jslint proposals

    variable names, start with lowercase, each new word starts with one uppercase

    var lastName, firstName;

    functions are a bit more "intresting", when it should be an object that would be a "class" of it's own, use:

    function Person() {
        // do something

    which you would call with:
    var person = new Person();

    function Person(firstName, lastName) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.getFullName = function() {
                return this.firstName + ' ' + this.lastName;

    some info on the jslint:

    it's always good if the editor you are working in is also helping you, Brackets is actually doing a pretty good job at it :)

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion