The best way to protect your Javascript is to put all your initialization code in closure and not set anything against global variables.
However, this provides only some guarantees against namespace conflicts at run time and is intended to be used as a good development practice.
You cannot trust client-side code; for anti-cheat behavior, you need to check the server-side incoming inputs. Users have 100% control over what works in their browsers, and this includes controls to change your code as they see fit.
source share