The es3 option

What does this option do?

The JSHint es3 option is used to tell JSHint that your code will be running in a ECMAScript 3 environment (as opposed to ECMAScript 5, which is the current version of the standard). It was introduced in JSHint 2.0.0. This will disallow the use of various ES5 features and enable various error messages that apply only to older ES3 environments (such as Internet Explorer 8 and below). The following example defines a setter and a getter on an object. These features were introduced in the ES5 specification:

/*jshint es3: true */
var person = {
    firstName: "James",
    lastName: "Brown",
    get name () {
        return this.firstName + " " + this.lastName;
    },
    set fullName (name) {
        var parts = name.split(" ");
        this.firstName = parts[0];
        this.lastName = parts[1];
    }
};

What errors can it cause?

When should I use this option?

The use of the es3 JSHint option can cause various error messages that would not be produced otherwise. This is a good thing, but only if your code has to run in environments that do not conform to ECMAScript 5.

Note that this is an enforcing option which means JSHint does not apply it by default. If you do not explicitly set this option to true JSHint will allow the use of ES5 features anywhere in your code. Also note that if you're using an older version of JSHint (prior to 2.0.0) this option will be unavailable and JSHint will disallow the use of ES5 features by default.

Recommendation

Set this option to true if you need to support Internet Explorer 8 and below.


About the author

James Allardice

This article was written by James Allardice, Software engineer at Tesco and orangejellyfish in London. Passionate about React, Node and writing clean and maintainable JavaScript. Uses linters (currently ESLint) every day to help achieve this.