Strangest language feature
Solution 1:
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.
Solution 2:
In JavaScript:
'5' + 3 gives '53'
Whereas
'5' - 3 gives 2
Solution 3:
In JavaScript, the following construct
return
{
id : 1234,
title : 'Tony the Pony'
};
returns is a syntax error due to the sneaky implicit semicolon insertion on the newline after undefined
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;