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

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


当前回答

在JavaScript中:

2 == [2]

//更陌生 2 == [[[2]]]

//和彻头彻尾的坚果 Var a = {"abc": 1}; A [[[["abc"]]]] === A ["abc"];//这也是正确的

幸运的是,stackoverflow.com网站上善良的人们向我解释了这一切:http:/stackoverflow.com/questions/1724255/why-does-2-2-in-javascript

其他回答

从Ruby中的随机类继承:

class RandomSubclass < [Array, Hash, String, Fixnum, Float, TrueClass].sample
   ...
end

(首次出现在Ruby的隐藏特性中)

2000年Perl Journal's obfusated Perl Contest的最佳参赛作品:

#:: ::-| ::-| .-. :||-:: 0-| .-| ::||-| .:|-. :||
open(Q,$0);while(<Q>){if(/^#(.*)$/){for(split('-',$1)){$q=0;for(split){s/\|
/:.:/xg;s/:/../g;$Q=$_?length:$_;$q+=$q?$Q:$Q*20;}print chr($q);}}}print"\n";
#.: ::||-| .||-| :|||-| ::||-| ||-:: :|||-| .:|

代码由作者在http://mysite.verizon.net/les.peters/id2.html详细解释

在JavaScript中,undefined是一个全局变量,其默认值为原始值undefined。你可以改变undefined的值:

var a = {};
a.b === undefined; // true because property b is not set
undefined = 42;
a.b === undefined; // false

由于undefined的可变性,通过typeof检查undefined通常是一个更好的主意:

var a = {};
typeof a.b == "undefined"; // always true

我想到的第一件事是“noop”,当我第一次看到它时,我的大脑也做了同样的事情!

在Perl中,你可以做到:

my $test = "Hello World";
substr($test, 0, 5) = "Goodbye";

print $test;

这在其他语言中可行吗?