The catch is that any JavaScript you encode, has to be decoded on the client side by the browser. Unless you are planning to ship some special browser plug-in such as an activeX control, you cannot do it. By comparison, encoded PHP is decoded on server side, and therefore it is universally readable by any standard browser.
However, what you can do without any special browser plug-ins, is to
obfuscate your JavaScript code. It is not the same as
encoding, but rather just making your JavaScript very hard to understand. I have been using a PHP library based on
Dean Edward's Packer. The primary function of Packet is to
compress your JavaScript (very large scripts download faster), but it also has very nice obfuscating functionality. I highly recommend it :
http://joliclic.free.fr/php/javascript-packer/en/