jQuery: writing plugins in ECMAScript strict mode

ECMAScript 5 introduces a new strict mode to aid JavaScript developers when writing their code. Strict mode prevents developers from following some bad coding habits, such as globals, thus increasing the level of consistency in your scripts. jQuery works perfectly well in strict mode but this is not a surprise. The question is: are we able to write standard code when developing our plugins or our jQuery scripts?

To answer this question, just put the following line at the top of your script or just inside the plugin's namespace:

'use strict';

If your console shows some errors at this point, then there's something wrong with your code. By following this practice we make sure that our code will be always standard compliant. Following this practice means that we're writing plugins the right way.

A sample plugin in strict mode can be found here.

Back to top