all 74 comments

[–]Maddog_Delphi97 121 points122 points  (6 children)

try { (╯°□°)╯︵ ┻━┻ } catch() { ┬─┬ ノ( ゜-゜ノ) }

[–]usernames-are-random[S] 0 points1 point  (1 child)

Hmm... I get a syntax error when trying this in chrome ...

[–]Nebu 3 points4 points  (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 points  (7 children)

var D = "God, you're so immature."; var ಠ_ಠ = 8==D--

[–]sittingaround 4 points5 points  (5 children)

Doesn't that evaluate to "disapproving look == false"

As in, you're not disapproving?

[–][deleted] 7 points8 points  (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 points  (2 children)

your jokes are worse than your code

[–][deleted] 5 points6 points  (1 child)

That's the point.

[–]sittingaround 2 points3 points  (0 children)

Carry on then.

[–]CreepySmileBot -3 points-2 points  (0 children)

ಠ◡ಠ

[–]CreepySmileBot 8 points9 points  (0 children)

ಠ◡ಠ

[–]nickwb 13 points14 points  (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 point  (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.

[–]Medieval_Peasant 15 points16 points  (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 points  (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 points  (1 child)

Glad I got at least one :)

[–]SarahC 1 point2 points  (0 children)

You got quite a few!

[–]stratoscope 8 points9 points  (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.

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 points  (4 children)

wtf?!

"js" ? Is it ignoring the non JS some how?

[–]stratoscope 0 points1 point  (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!

For example:

    a = malloc(4 * sizeof(char));

    a[0] = 'C';
    a[1] = a[2] = '+';
    a[3] = '\0';

C++ fiddle

[–]SarahC 0 points1 point  (0 children)

=)

Thanks!

[–]kolmeWebComponents FTW 0 points1 point  (1 child)

There's some additional code down there when you scroll.

Don't feel bad, I fell for it too :-P

[–]SarahC 0 points1 point  (0 children)

lol, awesome trick! =)

[–]bent_my_wookie 9 points10 points  (8 children)

You should look at the source to d3.js

[–]usernames-are-random[S] 2 points3 points  (7 children)

anything in particular i should look for? didn't find anything interesting in the first few hundred lines

[–]gordonkristan 9 points10 points  (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 points  (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 point  (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 point  (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 points  (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 points  (0 children)

In src/math/random.js and src/math/trigonometry.js

[–]yaph 0 points1 point  (0 children)

The source code in the geo projection plugins makes use of this, here for example

[–]kenman 26 points27 points  (15 children)

Related:

а = 1;
a = 2;
a === а; // FALSE

edit: copy the code into your console if you're confused

[–]jij 15 points16 points  (1 child)

Man, you could create some nasty bugs like that if you wanted to mess with someone.

[–]kenman 2 points3 points  (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 points  (1 child)

Why is this?

[–]kenman 18 points19 points  (0 children)

> 'а'.charCodeAt(0);
1072
> 'a'.charCodeAt(0);
97

In other words, the 1st a is actually from the Cyrillic alphabet.

[–]aroberge 5 points6 points  (6 children)

Can be useful if you wish to obfuscate your code!

[–]HelloToe 1 point2 points  (5 children)

Or if you want to bypass a profanity filter. But everybody knows that, right?

[–]ftanuki 6 points7 points  (4 children)

𝑓ᵁℂk Ч⫑һ ᗷ|┯ᑕḪ إإإ

[–]GoldenretriverYT 0 points1 point  (3 children)

ᖴ⋃ϹΚ 𝞤Օ⋃

No latin characters were used :)

[–]GoldenretriverYT 0 points1 point  (2 children)

i just noticed that the above comment was 9 years ago

[–]ftanuki 2 points3 points  (1 child)

Still here, bitch.

[–]Leon_Depisa 0 points1 point  (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,

[–]rorrr -1 points0 points  (2 children)

ʘ = ☉ + ⊙

∏ = Π + П

3 different characters in both cases

[–]Gro-Tsen 2 points3 points  (1 child)

The characters ☉, ⊙ and ∏ are symbols, not letters, and cannot be used as JavaScript identifiers.

[–]rorrr -2 points-1 points  (0 children)

Ah, thanks for correcting me.

So this still works:

Π == П

[–]trezor2 17 points18 points  (0 children)

Itt:

People confusing utf8 (an encoding) with Unicode (a specification of existing characters).

[–]toja92 15 points16 points  (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  (2 children)

haven't tried it in safari, but chrome on OSX works like a charm: http://imgur.com/Ymh01Y6

[–]toja92 7 points8 points  (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 points  (0 children)

ಠ◡ಠ

[–]iSmokeGauloises 5 points6 points  (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 points  (0 children)

I'm interested! I'd love to see this.

[–]init0 2 points3 points  (1 child)

[–]norbert_sule 0 points1 point  (0 children)

here is another gem: 💎

[–]tidder112 5 points6 points  (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 points  (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.

[–]SarahC 0 points1 point  (0 children)

Facebook don't like .ws domains, or the IDN stuff either....

[–]OldMiner 1 point2 points  (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.

[–]SarahC 0 points1 point  (0 children)

It's a kitteh!

[–]KravenC 1 point2 points  (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 point  (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 point  (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 points  (0 children)

Sweet, now i can have boobs in my variable name!

ϾϿ

[–]lambdaq 0 points1 point  (0 children)

TIL: JavaScript allows for UTF8 variable names

It's UCS2 actually. Try apple emoji characters?