There is a website "obfuscator.io", which obfuscates Javascript code. One of its functions is "Self-Defending". It turns a simple console.log() line into this:
var _0x2a3a06=function(){var _0x409993=!![];return function(_0xe0f537,_0x527a96){var _0x430fdb=_0x409993?function(){if(_0x527a96){var _0x154d06=_0x527a96['apply'](_0xe0f537,arguments);_0x527a96=null;return _0x154d06;}}:function(){};_0x409993=![];return _0x430fdb;};}();var _0x165132=_0x2a3a06(this,function(){var _0x46b23c=function(){var _0x4c0e23=_0x46b23c['constructor']('return\x20/\x22\x20+\x20this\x20+\x20\x22/')()['constructor']('^([^\x20]+(\x20+[^\x20]+)+)+[^\x20]}');return!_0x4c0e23['test'](_0x165132);};return _0x46b23c();});_0x165132();console['log']();
The code does work in Webkit Console, but when you beautify it using an application like "beautifier.io" or "de4js" and run it in the same console again, the code enters an infinite loop, essentially breaking the code. How does this work? Does it have something to do with the way beautifiers work, or with the way Javascript interpretes code?