update JavaScript implementation
micro-optimize JavaScript code; move CompareTo checks