在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?

请每个回答只回答一个特征。


当前回答

在c#中

Math.Round(2.5)==2

其他回答

在Java中(实际上,我最近在不同的SO帖子上写过这个):

    int x = 1 + + + + + + + + + + + + + 1;
    System.out.println(x);

JavaScript真值表:

''        ==   '0'           // false
0         ==   ''            // true
0         ==   '0'           // true
false     ==   'false'       // false
false     ==   '0'           // true
false     ==   undefined     // false
false     ==   null          // false
null      ==   undefined     // true
" \t\r\n" ==   0             // true

资料来源:Doug Crockford

在JavaScript中:

2 == [2]

// Even stranger
2 == [[[2]]]

// And down-right nutty
var a = { "abc" : 1 };
a[[[["abc"]]]] === a["abc"]; // this is also true

幸运的是,stackoverflow.com网站上善良的人们向我解释了这一切: 为什么2 ==[2]在JavaScript?

C和c++中的三联体。

int main() {
   printf("LOL??!");
}

这将打印LOL|,因为trigraph ??!转换为|。

在JavaScript中:

 '5' + 3 gives '53'

 '5' - 3 gives 2