Learning JavaScript from PHP - a Comparison | Lullabot - 0 views
-
In PHP, all variables are local in scope unless declared as global. JavaScript is opposite, and all variables are global unless declared with the var keyword.
-
JavaScript is a bit mixed concerning undeclared variables, if you attempt to modify or compare with an undeclared variable, the script will break entirely, but you can check the variable status using typeof() or in conditional statements containing only that variable.
- ...6 more annotations...
-
JavaScript only recognizes the keyword true in all lowercase. PHP accepts both uppercase and lowercase
-
PHP is not case-sensitive in function or class declarations, but JavaScript is case sensitive for these also.
-
JSON strings having become very popular as a faster alternative to XML, and can be read and created with the PHP functions json_encode() and json_decode().
-
Let's take one more look at defining an object in JavaScript and see how it can be used to compensate for the lack of associative arrays in JavaScript.
-
// Note that variables should always be// prefixed with "var" to define a local scope.for (var n = 0; n < 10; n++) { alert(n);}