becomes huge at some point. ▪ Simple mistakes can become showstoppers and waste hours of debugging. ▪ JavaScript has been developed in a rush ▪ JavaScript is loosely typed, values are typed, variables are not. ▪ Browser incompatibility is another source of bugs.
to identify code issues against set code conventions and chosen code style without actually executing or running it ▪ Also known as “lint” tools after a CLint code analysis tool for C language. ▪ Linter scan the code and reports about commonly made mistakes and potential bugs. ▪ The potential problem could be a syntax error, a bug due to implicit type conversion, a leaking variable or something else
issues in JavaScript and JSON ▪ Enforces established coding conventions ▪ Written in JavaScript by Douglas Crockford ▪ First released in 2002 and still in active development Usage: ▪ Online tool at jslint.com ▪ From command line, e.g. using Node.js ▪ Plugins for NetBeans, Notepad++, Sublime, TextMate
to be set directly in a script: For Node.js: Better way: /*global require, module, __dirname */ /*jslint node: true */ /*jslint nomen: true, debug: true, evil: false, vars: true */
b) { for (var i = 0; i < a.length; i++) { if (a[i] === b) { return i; } } return -1; }; Error: Problem at line 2 character 10: Move 'var' declarations to the top of the function. for (var i = 0; i < a.length; i++) { Problem at line 2 character 10: Stopping. (25% scanned).
code linter. ▪ Provides a better default validation rules ▪ Is easier to adjust for a particular coding style. ▪ Online tool at jshint.com. ▪ Also available as command-line tool via Node.js and as a plugin for various code editors
specify the configuration file via the --config flag ▪ use a special file .jshintrc ▪ put config into in package.json file under the jshintConfig property