Memory match in JavaScript