-1

I would like to add a comment block (/**/) in the middle of a javascript code for obfuscation reasonds.

I want this: alert(document.cookie);

to look like this: alert(document.co/**/okie);

but adding the comment block makes the code invalid. Why? Is there a way to do this?

  • 5
    Think of a comment block as a space: If a space breaks the code, then so will the comment. For example, this would be fine: `alert(/* comment */document./* comment */cookie/* comment */);` If you're trying to obfuscate JavaScript, comments are not the way to go (a simple JSLint will remove all comments anyways). The question should be: What methods are effective in JavaScript obfuscation, and in that case, your answer is [here](http://stackoverflow.com/questions/194397). If you're trying to hide the cookies, don't even try, a simple F12 -> Resources -> Cookies shows. – Dave Chen Aug 12 '14 at 18:10
  • @DaveChen You should post this as an answer mate. – Nick Rameau Aug 12 '14 at 18:17
  • @Troy No need, you already have! +1 – Dave Chen Aug 12 '14 at 18:17
  • @daveChen, your comment was so complete and it still all fit inside a comment block. Awesome! – Matthew Peters Aug 12 '14 at 18:21
  • @DaveChen Thanks that was very useful! I will try your obfuscation methods too. You couldve added your comment as an answer :P – TheEpicSurge Aug 13 '14 at 08:55

1 Answers1

2

Well it won't be cookie anymore dear. It's like adding a space in the middle of the property, therefore making it co okie. But it's fine if you do:

alert(/* Comment here */ document.cookie /* Or here */);
Nick Rameau
  • 1,258
  • 14
  • 23
  • 4
    I'd like to point out that you can have spaces between objects and their properties (just not spaces within the identifiers as you pointed out). `alert ( document . cookie ) ;` – Dave Chen Aug 12 '14 at 18:19