related concepts JavaScript ecosystem: node, databases You will not be an expert in JavaScript by the end of it unless you already are :) Main goal: arouse your curiosity
Version 4 - abandoned due to political differences 2005 - Jesse James Garrett writes the Ajax ECMAScript Version 5 (or 3.1) - Dec. 2009 'strict mode' to prevent common error constructs ECMAScript Version 6 - June 2015 classes, modules, generators, collections white paper
most type information at runtime Functional programming done by evaluating expressions Prototype based reusing is done by cloning existing objects "The world's most misunderstood programming language"
declared var x = 0; // Number x = "foo"; // String x = Symbol("foo"); // new in ES6 x = false; // Boolean x = null // Null x = undefined // Undefined x = {}; // Object - not a privimite type
or the {} literal Properties = Keys (Names) and Values Keys can be Strings and Symbols Values can be of any type var shirt = {}; shirt.size = 'LARGE' shirt['size'] > [ 'LARGE' ]
and always return a value Arguments are passed by value for primitive types function censor(text) { // all characters become # text = text.replace(/\w/g,"#"); return text; } var password = "foo" console.log(censor(password)); console.log(password); > '###' > 'foo' // password is unchanged
arround like any other type function add(a,b){ return a + b } function mul(a,b) { return a*b; } function compute(a,b, f){ return f(a,b); } compute(6,7,mul); > 42 compute (6,7, add) > 13
function-level scope Scope is defined statically - lexical scoping var x = 'spam'; // global scope function bar () { var x = 'eggs'; // local scope console.log(x); foo(); } function foo(){ console.log(x); // from global } bar() > 'eggs' > 'spam'
initialized Functions are 'hoisted' var x = 42; function foo() { bar(); if (!x) { // x === undefined var x = 0; } function bar(){ console.log(x); } console.log(x); } foo(); undefined > 0
for classes Prototype chain - objects are linked to their "prototype" var a = { x : 1 }; var b = Object.create(a); //link b to a b.x // shadowing a.x > 1 b.x = 2 // override with own implementation a.x > 1 a.y = 42; b.y // delegate to the protoptype > 42
= require("fs"); var server = http.createServer(function (request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); var data = fs.readFileSync('content.txt'); response.end(data+"\n"); }).listen(8000); console.log("Server running at http://127.0.0.1:8000/");
write scala and compile to JavaScript - Use future features now! TypeScript -> ES6 -> Babel -> ES5 Data visualization - function mul(a, b){ return a*b; } mul ("foo", "bar"); // NaN Scala.js Babel.js Crossfilter