Lecture Notes for CS142
Winter Quarter 2009
John Ousterhout
sum = 0; for (i = 1; i < 10; i++) { sum += i*i; }
function fac(x) { if (x <= 1) { return 1; } return x*fac(x-1); }
x = new Array(); y = ["a", 123, 65]
x = new Object() y = {name: "Alice", age: 23, state: "California"}
o = new Object(); o.name = "Alice"; o["age"] = 23;
<script type="text/javascript" src="code.js"></script>
<script type="text/javascript"> //<![CDATA[ Javascript goes here... //]]> </script>
<p onclick="alert('I told you you not to click on me!');"> Please do not click on this text.</p>
plus1 = function(value) { return value + 1; }plus1(24) returns 25
Object o = new Object(); o.count = 0; o.increment = function(inc) { if (inc == undefined) { inc = 1; } this.count += inc; return this.count; }o.increment() returns 1
function Rectangle(width, height) { this.width = width; this.height = height; } r = new Rectangle(26, 14);
Rectangle.prototype.area = function() { return this.width*this.height; }