Translate

Tuesday, July 12, 2011

Why do I get missing "use strict" statement error when I run my java script code through Crockford's JSLint?

Strict Mode is a new feature in ECMAScript 5 that allows you to place a program, or a function, in a "strict" operating context. This strict context prevents certain actions from being taken and throws more exceptions. Strict mode helps out in a couple ways:
  • It catches some common coding bloopers, throwing exceptions.
  • It prevents, or throws errors, when relatively "unsafe" actions are taken (such as gaining access to the global object).
  • It disables features that are confusing or poorly thought out.
Also note you can apply "strict mode" to the whole file... Or you can use it only for a specific function. Conclusion is it helps you make fewer errors, by detecting more things that could lead to breakages.

References:
  1. You can also look at article about that : John Resig - ECMAScript 5 Strict Mode, JSON, and More 
  2. You can try JSLint (The JavaScript Code Quality Tool) online by visiting: http://www.jslint.com/ 
  3. JSHint looks pretty interesting too: http://www.jshint.com/

    No comments:

    Post a Comment