Strangest language feature
What is, in your opinion, the most surprising, weird, strange or really "WTF" language feature you have encountered?
Please only one feature per answer.
In C, arrays can be indexed like so:
a[10]
which is very common.
However, the lesser known form (which really does work!) is:
10[a]
which means the same as the above.
In JavaScript:
'5' + 3 gives '53'
Whereas
'5' - 3 gives 2
In JavaScript, the following construct
return
{
id : 1234,
title : 'Tony the Pony'
};
returns undefined
is a syntax error due to the sneaky implicit semicolon insertion on the newline after return
. The following works as you would expect though:
return {
id : 1234,
title : 'Tony the Pony'
};
Even worse, this one works as well (in Chrome, at least):
return /*
*/{
id : 1234,
title : 'Tony the Pony'
};
Here's a variant of the same issue that does not yield a syntax error, just silently fails:
return
2 + 2;
链接地址: http://www.djcxy.com/p/1990.html
上一篇: StringBuilder和StringBuffer的区别
下一篇: 最奇特的语言功能