(aﾠ == 1 && a == 2 && ﾠa == 3) ever evaluate to
true? Well, today I found out it can. Run the below code and see for yourself.
Now let's look at seemingly the same code below. Try to run it. This time the expression does not evaluate to
true. So what changed?
The difference is actally really simple and much less mysterious once you figure out what's happening. Apparently, there is a Unicode character called Halfwidth Hangul Filler which is a Korean symbol and is, for all intents and purposes, invisible. So the reason why the first code snippet evaluates to
true is because the three variables
a are in fact three distinct variables. One of them is prepended with halfwidth hangul filler, another one is left intact and the third one is appended with the hidden character.
Now next time someone asks you whether
(aﾠ == 1 && a == 2 && ﾠa == 3) can ever equal to
true, you can answer them that yes, indeed it can (with a small caveat) 😀
Top comments (16)
Nice post, I wouldn't have thought about using an "invisible" character.
Now, for the curious people, there is also another way :)
Just for reference, the concepts used here are type coercion, closures and immediate function invocation.
a === 1 && a === 2 && a === 3evaluate to
Yes, you also can make true from
a === 1 && a === 2 && a === 3without invisible character, since, we have getter.
Precisely, nice catch.
Nice, interesting approach!
Nice! Way more useful and interesting than the actual post.
This is very cool and scary!
This feels a little clickbait-y. It feels the same as photographing two glasses of water after 3 hours in the freezer, and then saying, “we put two glasses of water in the freezer and one of them didn’t freeze!” And then revealing that one glass was actually full of vodka.
I don’t want to try to misunderstand the spirit of this article, but I don’t get why any of this is relevant.
letwill give you a hint
That's right! Although for the hint to be useful you have to know that
letthrows an exception if you try to redeclare a variable.
Does it not work if you set a to True since then 1,2,3 are cast to booleans and are evaluated at True aswell?
1,2,3are not casted to booleans as they are primitive types themselves.
In C bool is int is char
lol nice post :)
Maybe with the === operator?
As long as it's 3 different variables, the
===operator will not be helpful. This is a "magic" trick, not a bug ;)