Is it possible, perhaps by using some directive in the JavaScript code, to throw warnings or errors if variables are used without being declared first?
In case that isnt possible, is there perhaps some plugin to force Eclipse (or any other IDE) to detect undeclared variables?
Yes, it’s possible to do this using strict mode. You enable it by putting a statement containing the string literal
"use strict"at the top of a file or function to enable strict mode for that scope.This feature is now supported by all updated browsers. Older browsers wont’ throw an error since
"use strict";is a valid statement and is simply ignored by browsers that don’t support it. You can therefore use this to catch bugs while developing, but don’t rely on it throwing an exception in your users’ browsers.