Item | JavaScript | Java |
---|---|---|
How code is executed | Interpreted, each line of code is translated to machine code as it is used | |
How the language is used | Interactive within a web page | |
Code structure | flexible, in HTML tags, <script> or .js files | |
Starting code | function start( ) | |
Variable naming rules | Start with a letter, use numbers, letters, underscores. | |
Variable types | var x; variables can change type all variables are declared with var variables can be integer, float, string |
|
Global/local variables | variables only exist inside the { braces } where they are declared | |
Comments | // for a single line /* for multiple lines */ |
|
White space and style | ; marks the end of a statement { curly braces } group statements together indentation is good style, the computer doesn't care. |
|
print out | print("message"); println("the variable is " + x); |
|
read in values |
var wholeNumber = |
var wholeNumber = |
conditionals | ==, !=, <, >, <=, >=, &&, ||if(boolean condition){ statement;} else { statement; } |
|
Repeat with condition | while (boolean condition){ statements; } |
|
Repeat a fixed number of times | for ( var i = 0; i< limit ; i++){ statements; } |
|
Math | + - * / % | |
Modularization | Create your own functions.
function myFunction ( ) { statements; } |
|
OOP syntax | objectName.method(parameters) |