function f() { // OK - initialization to default value var x = null, y = undefined, z; x = {}; y = 23; // $ Alert y = 42; for (var p in x) y+p; // OK - assignment to global global = 42; var a = 23; a = 42; // $ Alert // OK - captured variable var b = 42; return function() { return b%2 }; } function g() { var x; x = 23, x += 19; var y = 42; } function h() { var x = false; try { this.mayThrow(); x = true; } catch(e) {} console.log(x); } function k(data) { for(var i=0;i .5) i = 23; } } function q() { var self = this, node, next; for (node = self.firstChild; node; ) { next = node.next; self.insert(node, self, true); node = next; } self.remove(); } function r() { var i; for (i = 0;;) console.log(i); } function s() { var container = document.createElement("div"), div = document.createElement("div"); doStuffWith(container, div); container = div = null; } // OK - the function expression could be made anonymous, but it's not // worth flagging this as a violation defineGetter(req, 'subdomains', function subdomains() { var hostname = this.hostname; if (!hostname) return []; var offset = this.app.get('subdomain offset'); var subdomains = !isIP(hostname) ? hostname.split('.').reverse() : [hostname]; return subdomains.slice(offset); }); // OK - assigning default values function t() { var x; x = false; x = ""; x = ''; x = 0; x = 0.0; x = -1; x = 42; return x; } // OK - unnecessary initialisation as type hint function u() { var x; x = []; x = {}; x = 42; return x; } // OK - assigning `undefined` function v() { var x; x = void 0; x = 42; return x; } !function(o) { var {x} = o; // $ Alert x = 42; return x; } // OK - assignments in dead code not flagged !function() { return; var x; x = 23; x = 42; return x; } (function(){ var x = (void 0); var y = ((void 0)); var z1 = z2 = (void 0); x = 42; y = 42; z1 = 42; z2 = 42; return x + y + z1 + z2; }); (function() { for (var a = (x, -1) in v = a, o); }); (function() { let [x] = [0], // $ SPURIOUS: Alert - flagged due to destructuring limitations y = 0; x = 42; y = 87; x; y; }); (function() { if (something()) { var nSign = foo; // $ Alert } else { console.log(nSign); } })()