Another one from the "this is not a syntax error" department.
var $myarray; var array = array(); $myarray = ; foreach(var i in myarray)
var user = 'Stoyan'; alert('hello ' . user);
This is obviously wrong, but the thing is that it's not a syntax error as one might expect. It alerts "undefined". Why is that?
Well, 'hello' is a string object. You can call methods and properties on it, like:
>>> 'hello'.toUpperCase() "HELLO" >>> 'hello'.length 5
And spaces don't matter...
>>> 'hello' . length 5 >>> 'hello' . toUpperCase() "HELLO"
'hello' . user is an attempt to access the "user" property of the string object 'hello'. This property doesn't exist, hence the "undefined" result.
$user = 'Stoyan'; echo 'Hello ' + $user; // prints 0