Below I have this one line of javascript. I want to know if there is another way I can write the name-id
tag (the element ID). So is there a different way I can write it, would would mean the same thing? Example in ASCII form?
I know in C I could write this in ASCII form.
var myname = document.getElementById("name-id").innerHTML;
You can find technical details of character encoding in current implementation of JavaScript in the official ECMAScript documentation.
ECMAScript code is expressed using Unicode, version 8.0.0 or later. ECMAScript source text is a sequence of code points. All Unicode code point values from U+0000 to U+10FFFF, including surrogate code points, may occur in source text where permitted by the ECMAScript grammars.
If less interested in technical aspects and in need of an obfuscator service, just use any of them or compare them. With minimal effort, you can produce something like this:
var _0x2245=['innerHTML','querySelector'],x="tell_me_a_nice_story"
.split("_"),y="#"+x[3][0]+"a"+x[1]+"-"+x[3][1];_0x2245.push(y+"d")
,function(x0,x){!function(x){for(;--x;)x0.push(x0.shift())}(++x)}(
_0x2245,4e3);var _0x1144=function(x0,x0x0){return _0x2245[x0-=0]},
myname=document[_0x1144("0x0")]( _0x1144("0x1"))[_0x2245[+2e0+0]];
console.log(myname);
<div id="name-id"
>Why would you do this?
</div>
If you really want to make it hard for others to read name-id
in your code, you can do a whole bunch of stuff on it.
You could write something completely different that contains all needed chars or all but one, which you'll add later, split that string into an array using some other unused letter as delimiter, take some array elements from their current position and place them at some other position, join a few, delete others and invert the value of others. Get creative.
By the end of second line above i have innerHTML
, querySelector
and #name-id
as members of the same array. Only name-id
was mambo-jambo-ed from tell_me_a_nice_story
but I could have easily produced innerHTML
and querySelector
from a slightly longer text, provided it contained most of the required letters. Think of it as a round of Scrabble.
The last line of the "code block" could be replaced with any of the following:
myname=document.getElementById(_0x2245[1].substring(1)).innerHTML;
myname=document.getElementById(_0x1144(1).substring(1)).innerHTML;
myname=document.querySelector(_0x1144(1)||_0x2245(1e0)).innerHTML;
myname=document.querySelector(_0x2245[`1`]||_0x1144(1)).innerHTML;
myname=document[_0x1144(0e3)](_0x2245[1-0]||"\_(ツ)_/").innerHTML;
or countless other variants, which "kind of" answer your question and fit the number of chars: 66
.
But, let's be very clear about it: anyone decent in JavaScript will have no problem debugging your code or console.log()
-ing the result of your final step, to get the value in a matter of seconds.
In all fairness, you can't really hide anything in JavaScript (frontend) without a server (to run a proper encryption service).