Some people weren't.
Keep this in mind...
void my_function() {char *data = malloc(1024);return; // oops! memory leak}
function my_function() {var data = [1, 2, 3, 4, ..., 1024];return; // data will be freed later}
function counter() {var n = 0;return function() {n++;return n;}}c = counter();c(); // returns 1c(); // returns 2
$("button").click(function(event) {// handle the click}
var handlers = [function() { ... },function() { ... }];var thingsToRun = {red: function() { ... },blue: function() { ... },green : function() { ... }}
function Thing() {this.name = "Bob";this.foo = [1138, 42, 1701];}var thing = new Thing();
(function () {var name = "Bob, the Closure String";$("button").click(function() {alert("My closure has a name variable: " + name)});})();
Garbage Collection
sin(3*pi/2)
How React uses referential transparency
function capitalize(list) {for (var i=0; i<list.length; i++) {list[i] = list[i].toUpperCase();}}
function upper(str) {return str.toUpperCase()}function capitalize(list) {return list.map(upper)}
$.get("http://example.com").then(doSomething).then(doSomethingElse).then(andFinish)
Example: Expensive CPU operation
function findNextPrime(previousPrime) {// do lots of workreturn nextPrime;}
function findNextPrime(previousPrime) {return function() {// do lots of workreturn nextPrime;}}
translated_string = trans("Hello, world!")
var x = {name: "Bob"};x.name = "Fred"; // Not allowed!
Whoa. Object.freeze()