Good:

    Use the same vocabulary for the same type of variable

    Bad:

    1. getUserInfo();
    2. getClientData();
    3. getCustomerRecord();

    Good:

    1. getUser();

    We will read more code than we will ever write. It’s important that the code we
    do write is readable and searchable. By not naming variables that end up
    being meaningful for understanding our program, we hurt our readers.
    Make your names searchable. Tools like
    buddy.js and

    can help identify unnamed constants.

    Bad:

    1. // Declare them as capitalized named constants.
    2. const MILLISECONDS_IN_A_DAY = 86400000;
    3. setTimeout(blastOff, MILLISECONDS_IN_A_DAY);

    Use explanatory variables

    Bad:

    1. const address = 'One Infinite Loop, Cupertino 95014';
    2. saveCityZipCode(address.match(cityZipCodeRegex)[1], address.match(cityZipCodeRegex)[2]);

    Good:

    1. const address = 'One Infinite Loop, Cupertino 95014';
    2. const cityZipCodeRegex = /^[^,\\]+[,\\\s]+(.+?)\s*(\d{5})?$/;
    3. const [, city, zipCode] = address.match(cityZipCodeRegex) || [];
    4. saveCityZipCode(city, zipCode);

    Explicit is better than implicit.

    Bad:

    Good:

    1. const locations = ['Austin', 'New York', 'San Francisco'];
    2. doStuff();
    3. doSomeOtherStuff();
    4. // ...
    5. // ...
    6. // ...
    7. dispatch(location);
    8. });

    Don’t add unneeded context

    Bad:

    1. const Car = {
    2. carMake: 'Honda',
    3. carModel: 'Accord',
    4. };
    5. function paintCar(car) {
    6. car.carColor = 'Red';
    7. }

    Good:

    1. make: 'Honda',
    2. model: 'Accord',
    3. color: 'Blue'
    4. };
    5. function paintCar(car) {
    6. car.color = 'Red';
    7. }

    Default arguments are often cleaner than short circuiting. Be aware that if you
    use them, your function will only provide default values for undefined
    arguments. Other “falsy” values such as '', "", false, null, 0, and
    NaN, will not be replaced by a default value.

    Bad:

    Good:

    1. function createMicrobrewery(name = 'Hipster Brew Co.') {
    2. }