Syntax
General
| PHP | Javascript | |
|---|---|---|
| Location | Embedded between <?php and ?> in a .php file | <head><script type="text /javascript"></script></head> <head><script type="text/javascript" src="xxx.js"></script></head> |
| Comments | // line comment /* multiline comment */ |
// line comment /* multiline comment */ |
| Case Sensitive | yes | |
| Line Endings | Lines optionally, but typically, end with a semicolon | |
| Output | echo "Hello"; or print "Hello"; | document.write("Hello"); |
Javascript locations
The <script> </script> Javascript can appear in either the <head> or <body> of an HTML document. If it's in the body section it generates page content.Operators
| PHP | Javascript | |
|---|---|---|
| Arithmetic | +, -, *, /, % | +, -, *, /, %, ++, -- |
| Assignment | =, +=, -=, *=, /=, %= | |
| Logical | and, or, xor, !, &&, || | &&, ||, ! |
| Conditional | (cond) ? (true) : (false) | |
| Comparison | ==, === (exactly equal), !=, >, <, >=, <= |
