Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: sockLen being miscalculated when removing sockets (#60)
Order of operations issue with + and ternary statements: console.log(0 + '' ? 'a' : 'b') // a The code: freeLen + this.sockets[name] ? this.sockets[name].length : 0; Is equivalent to: (freeLen + this.sockets[name]) ? this.sockets[name].length : 0; When `this.sockets[name]` exists, it is an array, `(freeLen + this.sockets[name])` evaluates to a string, which evaluates to a string (true). When it does not, `(freeLen + this.sockets[name])` evaluates to `NaN` (false). Either way, `freeLen` is ignored.
- Loading branch information