[英]Does anyone know what this in Javascript means? `ǀǀ+(ǀ==ǀ-->ǀ+ǀ<--ǀ==ǀ)+ǀǀ`
So I was looking at someones code on a website and while looking around, I saw this:所以我在网站上查看某人的代码,环顾四周,我看到了:
var ǀ = 1; var ǀǀ = 21; var s = ǀǀ+(ǀ==ǀ-->ǀ+ǀ<--ǀ==ǀ)+ǀǀ; document.writeln(s);
This somehow equates to 42?这在某种程度上等于 42? Does anyone know how they are doing this?
有谁知道他们是如何做到这一点的? I thought ||
我以为|| and |
和| where for
or
?在哪里
or
?
They're (ab)using a character that looks a whole lot like a vertical bar ( |
) such as what's used in "or" ( ||
).他们(ab)使用了一个看起来很像竖线(
|
)的字符,例如“或”( ||
)中使用的字符。
You could rewrite their code like this:你可以像这样重写他们的代码:
var a = 1; var b = 21; var s = b + (a == a-- > a + a < --a == a) + b; document.writeln(s);
or further simplified:或进一步简化:
var s = 21 + (1 == 1 > 0 + 0 < -1 == -1) + 21; document.writeln(s); // Even further simplified var s = 21 + (true > false < true) + 21; document.writeln(s); // Clean up that middle case var s = 21 + (false) + 21; document.writeln(s); // Coerce to a number var s = 21 + 0 + 21; document.writeln(s); // Last simplification var s = 21 + 21; document.writeln(s);
No special operators.没有特殊的运算符。 Just normal ones smushed together with odd-looking variable names.
只是普通的与奇怪的变量名称混在一起。
ǀ
and ǀǀ
are (Unicode) variable names. ǀ
和ǀǀ
是 (Unicode) 变量名。
Space it out:把它隔开:
var ǀ = 1;
var ǀǀ = 21;
var s = ǀǀ + (ǀ == ǀ-- > ǀ + ǀ < --ǀ == ǀ) + ǀǀ;
Apply operator precedence and associativity:应用运算符优先级和结合性:
var ǀ = 1;
var ǀǀ = 21;
var s = (ǀǀ + ((ǀ == ((ǀ-- > (ǀ + ǀ)) < --ǀ)) == ǀ)) + ǀǀ;
Apply order of evaluation:应用评估顺序:
var a = ǀǀ + ((ǀ == ((ǀ-- > (ǀ + ǀ)) < --ǀ)) == ǀ);
var s = a + ǀǀ;
var b = (ǀ == ((ǀ-- > (ǀ + ǀ)) < --ǀ)) == ǀ;
var a = ǀǀ + b;
var c = ǀ == ((ǀ-- > (ǀ + ǀ)) < --ǀ);
var b = c == ǀ;
var d = (ǀ-- > (ǀ + ǀ)) < --ǀ;
var c = ǀ == d;
var e = ǀ-- > (ǀ + ǀ);
var d = e < --ǀ;
var g = ǀ--;
var f = ǀ + ǀ;
var e = g > f;
Evaluate:评估:
var ǀ = 1;
var ǀǀ = 21;
var g = ǀ--;
var f = ǀ + ǀ;
var e = g > f;
var d = e < --ǀ;
var c = ǀ == d;
var b = c == ǀ;
var a = ǀǀ + b;
var s = a + ǀǀ;
var ǀ = 0;
var ǀǀ = 21;
var g = 1;
var f = ǀ + ǀ;
var ǀ = 0;
var ǀǀ = 21;
var f = 0 + 0;
var e = g > f;
var ǀ = 0;
var ǀǀ = 21;
var e = 1 > 0; // true
var d = e < --ǀ;
var ǀ = -1;
var ǀǀ = 21;
var d = true < -1; // false
var c = ǀ == d;
var ǀ = -1;
var ǀǀ = 21;
var c = -1 == -1; // true
var b = c == ǀ;
var ǀ = -1;
var ǀǀ = 21;
var b = true == -1; // false
var a = ǀǀ + b;
var ǀ = -1;
var ǀǀ = 21;
var a = 21 + false; // 21
var s = a + ǀǀ;
var ǀ = -1;
var ǀǀ = 21;
var s = 21 + 21; // 42
It is a joke (a bad one).这是一个笑话(一个坏的)。 It isn't an operator.
它不是运营商。 It is a collection of variable and operators put together to look intentionally confusing.
它是一组变量和运算符放在一起看起来故意混淆。
It is taking advantage of the visual similarities between ǀ
(U+01C0 : LATIN LETTER DENTAL CLICK {pipe}) which is a character you can use in a variable name and |
它利用了
ǀ
(U+01C0 : LATIN LETTER DENTAL CLICK {pipe}) 之间的视觉相似性,这是一个可以在变量名中使用的字符和|
(U+007C : VERTICAL LINE {vertical bar}) which is an operator. (U+007C : VERTICAL LINE {vertical bar}) 这是一个运算符。
This is a mixture of obfuscation, and some abuse of weak typing.这是混淆和一些弱类型滥用的混合体。
First, ǀ
and ǀǀ
here are just variables with funny names - names that look a bit like, but aren't actually, the common character |
首先,这里的
ǀ
和ǀǀ
只是名称很有趣的变量 - 名称看起来有点像,但实际上并不是常见的字符|
, which would be an operator. ,这将是一个运算符。 So let's swap them out:
所以让我们换掉它们:
var a = 1;
var b = 21;
var s = b+(a==a-->a+a<--a==a)+b;
document.writeln(s);
Now we have various operations on one line, we need to work out the precedence of the different operators , so we can break it down in the right order.现在我们在一行上有各种操作,我们需要计算出不同操作符的优先级,以便我们可以按正确的顺序分解它。 The operators we have, in order of highest to lowest precedence, are:
我们拥有的运算符按优先级从高到低是:
(
... )
to give a section higher precedence (
... )
给予部分更高的优先级--
--
--
--
+
>
and <
(left to right) >
和<
(从左到右)==
(multiple times, left to right) ==
(多次,从左到右) So we can calculate the sum in this order:所以我们可以按这个顺序计算总和:
21 + (something) + 21
21 + (something) + 21
a--
gives 1
, but changes a
to 0 ( b+(a==1>a+a<--a==a)+b
) a--
给出1
,但将a
更改为 0 ( b+(a==1>a+a<--a==a)+b
)--a
changes a
to -1
and gives -1
( b+(a==1>a+a<-1==a)+b
) --a
将a
更改为-1
并给出-1
( b+(a==1>a+a<-1==a)+b
)a
is now -1
, so the very middle becomes -1+-1
( b+(a==1>-1+-1<-1==a)+b
) which is -2
( b+(a==1>-2<-1==a)+b
) a
现在是-1
,所以中间变成-1+-1
( b+(a==1>-1+-1<-1==a)+b
) 即-2
( b+(a==1>-2<-1==a)+b
)1>-2
is true
( b+(a==true<-1==a)+b
) 1>-2
为true
( b+(a==true<-1==a)+b
)true<-1
is false
because true
is treated as 1
( b+(a==false==a)+b
) true<-1
为false
因为true
被视为1
( b+(a==false==a)+b
)a
is -1
, but false
is 0
, so a==false
is like saying -1==0
, which is false
( b+(false==a)+b
) a
是-1
,但false
是0
,所以a==false
就像说-1==0
,这是false
( b+(false==a)+b
)false==a
is again false
( b+(false)+b
) false==a
是false
( b+(false)+b
)false
is 0, so b + 0 + b
is 21 + 0 + 21
is 42
false
为 0,因此b + 0 + b
为21 + 0 + 21
为42
Interestingly, the in-place modification of a
makes this open to various interpretations.有趣的是,
a
的就地修改使这对各种解释开放。 For instance, it might be that all the unmodified a
s are substituted as 1
(ie before the a++
), giving some variations:例如,可能所有未修改的
a
都被替换为1
(即在a++
之前),给出了一些变化:
a
as 1
, the very middle is 1+1
( b+(a==1>1+1<-1==a)+b
) which is 0
( b+(a==1>2<-1==a)+b
)a
作为1
,中间是1+1
( b+(a==1>1+1<-1==a)+b
) 即0
( b+(a==1>2<-1==a)+b
)1>2
is false
( b+(a==false<-1==a)+b
) 1>2
为false
( b+(a==false<-1==a)+b
)false<-1
is still false
, so we get back to our original sequencefalse<-1
仍然是false
,所以我们回到我们原来的序列
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.