creative technology / new media
[_] readme workshop(s) project(s) CA1 CA2 CA3 CA4 CA5 course(s) - creative exploration(s) / serious games / ethic(s) - resource(s) _ # @ !

theme(s) / editor / tutorial(s)

quick reference to basic javascript commands.
 Comments ``` // this is a one-line comment /* this comment could contain linebreaks */ ``` Constants numbers 12.3 and strings "hi", "hi".charAt(0) is "h" Variables start with a letter, then use letters, digits or _ (declared with var) Expressions built from +, -, *, /, pow(x,y), sqrt(), PI, E, log(), floor(), ceil(), random(), sin(), cos(), tan(), atan() and constants, variables, functions Assignments ` v = expression; ` Blocks ``` { statement 1; ... statement n; } ``` Conditions expression == expression or <=, <, >, >=, !=... or !cond, cond1 && cond2, cond1 || cond2 if - else ``` if (condition) block 1 else block 2 // optional ``` for-loops ``` for (var i=start; endcondition; i++) block ``` while-loops ``` while (condition) block ``` Functions ``` f = function(v1, ..., vn) { statement 1; ... return expression; } ``` Lists (arrays) ``` a = [1,2,"hi"] a[0] is 1, a.length is 3, a+[4] is [1,2,"hi",4] ``` Objects(hash tables) ``` object = {attribute:expression, method:function} a = {x:2, y:3, s:function(){return this.x+this.y}} a.x is 3, a["x"] is 3, a.s() is 5 ``` Output ``` write("Hello"); writeln(" world"); ```
```