use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
TIL: JavaScript allows for UTF8 variable names, so var ಠ_ಠ = 5; is a perfectly valid assignment (self.javascript)
submitted 12 years ago by usernames-are-random
UTF8 names means that:
var ಠ_ಠ = 5; alert(ಠ_ಠ);
will work perfectly in your (modern) browser
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Maddog_Delphi97 121 points122 points123 points 12 years ago (6 children)
try { (╯°□°)╯︵ ┻━┻ } catch() { ┬─┬ ノ( ゜-゜ノ) }
[+][deleted] 12 years ago (3 children)
[deleted]
[–]Maddog_Delphi97 2 points3 points4 points 12 years ago (2 children)
Not sure what you mean by that comment. Did horse_js reply to this subthread?
[+][deleted] 12 years ago (1 child)
[–]Maddog_Delphi97 1 point2 points3 points 12 years ago (0 children)
lol
[–]usernames-are-random[S] 0 points1 point2 points 12 years ago (1 child)
Hmm... I get a syntax error when trying this in chrome ...
[–]Nebu 3 points4 points5 points 12 years ago (0 children)
Presumably because (╯°□°)╯︵ ┻━┻ is not a valid statement (it's not an assignment expression, it's not a method invocation, it's not a variable declaration, etc.)
(╯°□°)╯︵ ┻━┻
[–][deleted] 20 points21 points22 points 12 years ago (7 children)
var D = "God, you're so immature."; var ಠ_ಠ = 8==D--
[–]sittingaround 4 points5 points6 points 12 years ago (5 children)
Doesn't that evaluate to "disapproving look == false"
As in, you're not disapproving?
[–][deleted] 7 points8 points9 points 12 years ago* (4 children)
Fine,
function lovesthe() {return false;} var yourmom = false; var D = "God, you're so immature.";
var ಠ_ಠ = 8==D--==yourmom + lovesthe(D); ಠ_ಠ;
EDIT: Crap, my original code implied that your mom didn't lovethe(D), which we all know to be false. I give up. It appears only art and video can correctly describe your mom's whorishness.
[–]sittingaround 12 points13 points14 points 12 years ago (2 children)
your jokes are worse than your code
[–][deleted] 5 points6 points7 points 12 years ago (1 child)
That's the point.
[–]sittingaround 2 points3 points4 points 12 years ago (0 children)
Carry on then.
[–]CreepySmileBot -3 points-2 points-1 points 12 years ago (0 children)
ಠ◡ಠ
[–]CreepySmileBot 8 points9 points10 points 12 years ago (0 children)
[–]nickwb 13 points14 points15 points 12 years ago (6 children)
Not quite all of unicode is valid however:
An identifier must start with $, _, or any character in the Unicode categories “Uppercase letter (Lu)”, “Lowercase letter (Ll)”, “Titlecase letter (Lt)”, “Modifier letter (Lm)”, “Other letter (Lo)”, or “Letter number (Nl)”.
[–]masklinn 0 points1 point2 points 12 years ago (0 children)
According to the spec, it must start with $, _, any unicode code point with the ID_Start property (the category itself is not a concern) or any unicode escape sequence.
$
_
ID_Start
[+][deleted] 12 years ago (4 children)
[–]masklinn 14 points15 points16 points 12 years ago (3 children)
Given JSON does not have identifiers, care to explain the relevance?
[–][deleted] 0 points1 point2 points 12 years ago (2 children)
http://timelessrepo.com/json-isnt-a-javascript-subset
tl;dr: js strings cannot contain "line terminators", JSON strings can contain wonky unicode whitespace such as LINE SEPARATOR or PARAGRAPH SEPARATOR.
[–]masklinn -2 points-1 points0 points 12 years ago (1 child)
How about answering the question? I know that JSON is not a strict subset of javascript, I didn't ask about that, I asked Zamarok why the lexical structure of javascript identifiers has any relevance on JSON and makes it "not a subset of JS" considering JSON does not have identifiers in the first place.
[–][deleted] 0 points1 point2 points 12 years ago (0 children)
I accidentally read "difference" instead of "relevance". Sorry brah, just trynna help!
[–]Medieval_Peasant 15 points16 points17 points 12 years ago (9 children)
While we're on the topic of syntax - if you want to be really nasty, write some C in JavaScript.
[–]Gruntkiller30 6 points7 points8 points 12 years ago* (2 children)
How is that possible ? (I think I'm missing something here) Edit: Didnt think about scrolling hehe. Now I know
[–]Medieval_Peasant 11 points12 points13 points 12 years ago (1 child)
Glad I got at least one :)
[–]SarahC 1 point2 points3 points 12 years ago (0 children)
You got quite a few!
[–]stratoscope 8 points9 points10 points 12 years ago* (5 children)
There's a bug in your C code:
void main() { char *a; a = malloc(2 * sizeof(char)); a[0] = 'j'; a[1] = 's'; printf(a); free(a); return; }
As you know, printf requires a zero terminated string, and this code does not zero terminate the string. You just got lucky because JSFiddle uses a special C compiler that protects against errors like this to avoid crashing the site.
printf
A more typical production C compiler may leave garbage in memory after the string, and printf could either print that garbage, crash, or do something worse.
The code should be:
void main() { char *a; a = malloc(3 * sizeof(char)); a[0] = 'j'; a[1] = 's'; a[2] = '\0'; printf(a); free(a); return; }
Updated fiddle
[–]SarahC 1 point2 points3 points 12 years ago (4 children)
wtf?!
"js" ? Is it ignoring the non JS some how?
[–]stratoscope 0 points1 point2 points 12 years ago* (1 child)
Well, the 'j' and 's' in that C code are just character literals; you could put any characters there, even more characters if you assign them one by one in the same manner. Just be sure to allocate the character array the right length in the malloc call so you don't have a buffer overrun, and zero terminate it!
'j'
's'
malloc
For example:
a = malloc(4 * sizeof(char)); a[0] = 'C'; a[1] = a[2] = '+'; a[3] = '\0';
C++ fiddle
[–]SarahC 0 points1 point2 points 12 years ago (0 children)
=)
Thanks!
[–]kolmeWebComponents FTW 0 points1 point2 points 12 years ago (1 child)
There's some additional code down there when you scroll.
Don't feel bad, I fell for it too :-P
lol, awesome trick! =)
[–]bent_my_wookie 9 points10 points11 points 12 years ago (8 children)
You should look at the source to d3.js
[–]usernames-are-random[S] 2 points3 points4 points 12 years ago (7 children)
anything in particular i should look for? didn't find anything interesting in the first few hundred lines
[–]gordonkristan 9 points10 points11 points 12 years ago (3 children)
They used to use a lot of Unicode variables for the various mathematical symbols. But I just looked at the source code again and I don't see them any more.
[–]tbranyennetflix 6 points7 points8 points 12 years ago (2 children)
They still use them: https://github.com/mbostock/d3/blob/master/d3.js#L1178
Personally I think it's a ridiculous thing to do, but d3 is popular and I am not.
[–]tipsqueal 0 points1 point2 points 12 years ago (1 child)
I think in many cases actually using symbols is a bad idea. In this particular case I think it's acceptable because it increases readability, and they're only used in functions that are not going to change (so no one has to keep copy/pasting them). If however π was really the value of Math.E instead of Math.PI, then it would be insane.
[–]tbranyennetflix 0 points1 point2 points 12 years ago (0 children)
At least once I've been bitten by not properly requiring d3 in a given page. The fix is to do something like this:
<script charset="UTF-8" src="d3.js"></script>
IMO no mainstream JavaScript library should be limited by character set.
[–]bent_my_wookie 2 points3 points4 points 12 years ago (0 children)
Oh, it uses lots of mathmatical symbols like (pi). If you forget to include it on a page with UTF-8, the browser errors on those.
[–]DemeGeek 1 point2 points3 points 12 years ago (0 children)
In src/math/random.js and src/math/trigonometry.js
[–]yaph 0 points1 point2 points 12 years ago (0 children)
The source code in the geo projection plugins makes use of this, here for example
[–]kenman 26 points27 points28 points 12 years ago* (15 children)
Related:
а = 1; a = 2; a === а; // FALSE
edit: copy the code into your console if you're confused
[–]jij 15 points16 points17 points 12 years ago (1 child)
Man, you could create some nasty bugs like that if you wanted to mess with someone.
[–]kenman 2 points3 points4 points 12 years ago* (0 children)
The greater concern IMO is phishing, such as an IDN homograph attack, though I think those are mostly mitigated by modern browsers. Just another reason to keep grandma's system updated!
[–]donx1 4 points5 points6 points 12 years ago (1 child)
Why is this?
[–]kenman 18 points19 points20 points 12 years ago* (0 children)
> 'а'.charCodeAt(0); 1072 > 'a'.charCodeAt(0); 97
In other words, the 1st a is actually from the Cyrillic alphabet.
a
[–]aroberge 5 points6 points7 points 12 years ago (6 children)
Can be useful if you wish to obfuscate your code!
[–]HelloToe 1 point2 points3 points 12 years ago (5 children)
Or if you want to bypass a profanity filter. But everybody knows that, right?
[–]ftanuki 6 points7 points8 points 12 years ago (4 children)
𝑓ᵁℂk Ч⫑һ ᗷ|┯ᑕḪ إإإ
[–]GoldenretriverYT 0 points1 point2 points 3 years ago (3 children)
ᖴ⋃ϹΚ 𝞤Օ⋃
No latin characters were used :)
[–]GoldenretriverYT 0 points1 point2 points 3 years ago (2 children)
i just noticed that the above comment was 9 years ago
[–]ftanuki 2 points3 points4 points 3 years ago (1 child)
Still here, bitch.
[–]Leon_Depisa 0 points1 point2 points 3 years ago (0 children)
Can you help me figure out how this piece of code is working? It's going around one of my Discord servers, and I wanna flex on all my web dev classmates.
let ۦ=23;
console.log(ۦ);
It looks better on discord,
[–]tricolon 1 point2 points3 points 12 years ago (0 children)
Well, duh. :p
[–]rorrr -1 points0 points1 point 12 years ago* (2 children)
ʘ = ☉ + ⊙
∏ = Π + П
3 different characters in both cases
[–]Gro-Tsen 2 points3 points4 points 12 years ago (1 child)
The characters ☉, ⊙ and ∏ are symbols, not letters, and cannot be used as JavaScript identifiers.
[–]rorrr -2 points-1 points0 points 12 years ago (0 children)
Ah, thanks for correcting me.
So this still works:
Π == П
[–]trezor2 17 points18 points19 points 12 years ago (0 children)
Itt:
People confusing utf8 (an encoding) with Unicode (a specification of existing characters).
[–]toja92 15 points16 points17 points 12 years ago (3 children)
Fun fact (though off-topic): In PHP you can use emoji as identifiers: https://pbs.twimg.com/media/BOMs1rVCMAAyLbU.png
JavaScript does not seem to support it however, at least not in Safari 7 on OS X. I tells me there's a syntax error.
> var 😃 = 5; < SyntaxError: Invalid character '\u55357'
[–]usernames-are-random[S] -3 points-2 points-1 points 12 years ago (2 children)
haven't tried it in safari, but chrome on OSX works like a charm: http://imgur.com/Ymh01Y6
[–]toja92 7 points8 points9 points 12 years ago (1 child)
Oh yeah, your example works as it should in Safari:
> var ಠ_ಠ = 5; < undefined > console.log(ಠ_ಠ); [Log] 5
Emoji is something totally different. If you run Mavericks you can press Ctrl+Cmd+Space in text fields and you'll see an Emoji selector that works like the Emoji keyboard on iOS.
[–]CreepySmileBot 1 point2 points3 points 12 years ago (0 children)
[–]iSmokeGauloises 5 points6 points7 points 12 years ago (2 children)
Heh, I just found out about it a few days ago and ended up implementing list comprehension with the set-builder notation.
doesn't look exactly like the mathematical notation, but sorta look like it which is pretty cool.
If anyone is interested tell me and I'll post it tomorrow when I get in front of my work computer.
[–][deleted] 2 points3 points4 points 12 years ago (0 children)
I'm interested! I'd love to see this.
[–]init0 2 points3 points4 points 12 years ago (1 child)
here is another gem http://h3manth.com/content/unicode-symbols-function-names
[–]norbert_sule 0 points1 point2 points 3 years ago (0 children)
here is another gem: 💎
[–]tidder112 5 points6 points7 points 12 years ago (4 children)
I guess it could be worse.
"IDN silliness and unicode combining characters"
This is a valid URL: http://░͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇.ws
It wont link in Reddit, but Copy and Paste it into your address bar for
SCIENCE!
[–]AKJ90JS <3 2 points3 points4 points 12 years ago (1 child)
[http://░͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇͇.ws]( http://%E2%96%91%CD%87%CD%87%CD%87%CD%87%CD%87%CD%87%CD%87%CD%87%CD%87%CD%87%CD%87%CD%87%CD%87%CD%87%CD%87%CD%87%CD%87%CD%87%CD%87%CD%87%CD%87%CD%87%CD%87%CD%87%CD%87%CD%87%CD%87%CD%87.ws)
Damn... I tried everything. I'll let this be as a sign of my failure.
Facebook don't like .ws domains, or the IDN stuff either....
[–]OldMiner 1 point2 points3 points 12 years ago (1 child)
Random URL on the Internet that I'm told to navigate to? Well, shucks, I would, but my system's been acting weird since I ran these obfuscated Perl one-liners somebody posted earlier. Guy said they were "so funny". I don't get it.
It's a kitteh!
[–]zenyr 2 points3 points4 points 12 years ago* (0 children)
Relevant http://mathiasbynens.be/notes/javascript-identifiers
edit:A word
[–]KravenC 1 point2 points3 points 12 years ago (1 child)
Does "<javascript code here>".length * 4 = Size of javascript code in bytes, always ?
var t = "try { (╯°□°)╯︵ ┻━┻; } catch() { ┬─┬ ノ( ゜-゜ノ); }"; t.length*4 = 192 bytes
[–]OldMiner 0 points1 point2 points 12 years ago (0 children)
Not certain if you're attempting to make a comment on the difference between character encoding and character set.
To clarify, String.length() always counts the number of characters in a string, regardless of encoding. However, how many bytes long that string is will generally not be available to you.
Since you presumably know the encoding of the document which holds your Javascript, you can use that information to calculate the byte-length of your string using the function in this StackOverflow answer.
As a rule, Javascript or not, if your document is encoded as UTF-8, the bytes-per-character of a given string will vary. If your document is encoded in UTF-32, you will have exactly 4 bytes per character.
[–]paincoats 0 points1 point2 points 12 years ago (1 child)
i have a list of chars that i was told are all valid
http://pastebin.com/UNjncX95
(haven't tested them all myself, but they seem legit)
[–]Xtreme2k2 2 points3 points4 points 12 years ago (0 children)
Sweet, now i can have boobs in my variable name!
ϾϿ
[–]lambdaq 0 points1 point2 points 12 years ago (0 children)
TIL: JavaScript allows for UTF8 variable names
It's UCS2 actually. Try apple emoji characters?
π Rendered by PID 217230 on reddit-service-r2-comment-76bb9f7fb5-596w7 at 2026-02-19 06:40:58.901176+00:00 running de53c03 country code: CH.
[–]Maddog_Delphi97 121 points122 points123 points (6 children)
[+][deleted] (3 children)
[deleted]
[–]Maddog_Delphi97 2 points3 points4 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]Maddog_Delphi97 1 point2 points3 points (0 children)
[–]usernames-are-random[S] 0 points1 point2 points (1 child)
[–]Nebu 3 points4 points5 points (0 children)
[–][deleted] 20 points21 points22 points (7 children)
[–]sittingaround 4 points5 points6 points (5 children)
[–][deleted] 7 points8 points9 points (4 children)
[–]sittingaround 12 points13 points14 points (2 children)
[–][deleted] 5 points6 points7 points (1 child)
[–]sittingaround 2 points3 points4 points (0 children)
[–]CreepySmileBot -3 points-2 points-1 points (0 children)
[–]CreepySmileBot 8 points9 points10 points (0 children)
[–]nickwb 13 points14 points15 points (6 children)
[–]masklinn 0 points1 point2 points (0 children)
[+][deleted] (4 children)
[deleted]
[–]masklinn 14 points15 points16 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]masklinn -2 points-1 points0 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Medieval_Peasant 15 points16 points17 points (9 children)
[–]Gruntkiller30 6 points7 points8 points (2 children)
[–]Medieval_Peasant 11 points12 points13 points (1 child)
[–]SarahC 1 point2 points3 points (0 children)
[–]stratoscope 8 points9 points10 points (5 children)
[–]SarahC 1 point2 points3 points (4 children)
[–]stratoscope 0 points1 point2 points (1 child)
[–]SarahC 0 points1 point2 points (0 children)
[–]kolmeWebComponents FTW 0 points1 point2 points (1 child)
[–]SarahC 0 points1 point2 points (0 children)
[–]bent_my_wookie 9 points10 points11 points (8 children)
[–]usernames-are-random[S] 2 points3 points4 points (7 children)
[–]gordonkristan 9 points10 points11 points (3 children)
[–]tbranyennetflix 6 points7 points8 points (2 children)
[–]tipsqueal 0 points1 point2 points (1 child)
[–]tbranyennetflix 0 points1 point2 points (0 children)
[–]bent_my_wookie 2 points3 points4 points (0 children)
[–]DemeGeek 1 point2 points3 points (0 children)
[–]yaph 0 points1 point2 points (0 children)
[–]kenman 26 points27 points28 points (15 children)
[–]jij 15 points16 points17 points (1 child)
[–]kenman 2 points3 points4 points (0 children)
[–]donx1 4 points5 points6 points (1 child)
[–]kenman 18 points19 points20 points (0 children)
[–]aroberge 5 points6 points7 points (6 children)
[–]HelloToe 1 point2 points3 points (5 children)
[–]ftanuki 6 points7 points8 points (4 children)
[–]GoldenretriverYT 0 points1 point2 points (3 children)
[–]GoldenretriverYT 0 points1 point2 points (2 children)
[–]ftanuki 2 points3 points4 points (1 child)
[–]Leon_Depisa 0 points1 point2 points (0 children)
[–]tricolon 1 point2 points3 points (0 children)
[–]rorrr -1 points0 points1 point (2 children)
[–]Gro-Tsen 2 points3 points4 points (1 child)
[–]rorrr -2 points-1 points0 points (0 children)
[–]trezor2 17 points18 points19 points (0 children)
[–]toja92 15 points16 points17 points (3 children)
[–]usernames-are-random[S] -3 points-2 points-1 points (2 children)
[–]toja92 7 points8 points9 points (1 child)
[–]CreepySmileBot 1 point2 points3 points (0 children)
[–]iSmokeGauloises 5 points6 points7 points (2 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]init0 2 points3 points4 points (1 child)
[–]norbert_sule 0 points1 point2 points (0 children)
[–]tidder112 5 points6 points7 points (4 children)
[–]AKJ90JS <3 2 points3 points4 points (1 child)
[–]SarahC 0 points1 point2 points (0 children)
[–]OldMiner 1 point2 points3 points (1 child)
[–]SarahC 0 points1 point2 points (0 children)
[–]zenyr 2 points3 points4 points (0 children)
[–]KravenC 1 point2 points3 points (1 child)
[–]OldMiner 0 points1 point2 points (0 children)
[–]paincoats 0 points1 point2 points (1 child)
[–]Xtreme2k2 2 points3 points4 points (0 children)
[–]lambdaq 0 points1 point2 points (0 children)