JavaScript for Web Analytics
Beginners Guide by Lukáš Čech
Lukáš Čech
(in numbers)
Male human (35)
Internet (20)
Etnetera (11)
Analytics (8)
Father (4)
MeasureCamp (3)
Double father (2)
*) as of 16.9.2017
Inspired by
Principy JavaScriptu
by Riki Fridrich
JavaScript is a high-level,
dynamic, weakly typed, object-
based, multi-paradigm, and
interpreted programming
language.
High-level
Dynamic
Interpreted
Weakly-typed
var x = [0];
x == x // true
x == !x // true
['',''] == ',' // true
['',''] === ',' // false
'5' - 3 // 2
'5' + 3 // 53
Object-based
Multi-paradigm
The basics of the basics – Primitive types
Undefined
Null
Boolean
Number
String
The basics – Reference types
Object*) (Associative Array)
→ Array
→ Function (IIFE1)
Regex
*) JSON2
Primitive
var key = 1;
function add (input) {
input++;
}
add(key);
console.log(key); // 1
var obj = {key: 1};
function add (input) {
input.key++;
}
add(obj);
console.log(obj.key); // 2
Reference
var obj = {key: 1};
function add (input) {
input.key++;
}
add(JSON.parse(JSON.stringify(obj)));
console.log(obj.key); // 1
length
slice(start, end)
substring(start, end)
substr(start, length)
indexOf(), lastIndexOf()
split(separator), concat()
search(), replace()
Array Methods and PropertiesString Methods and Properties
length
push(item), pop()
shift(), unshift()
slice(), splice()
indexOf()
join(), concat()
sort(), reverse()
Operations & Comparisons
+, -, *, /, %, ++, --
=, +=, -=, *=, /=, %=
==, ===, !=, !==, <, >, >=, <=
&&, ||, !, typeof, instanceof
?
&, |, ~, ^, <<, >>, >>>
Still the basics
Control Structures
Functions
if-else, switch
for, for/in
while, do/while
try..catch, throw
The almost-nerdy stuff
Hoisting
Scope
Scope Chain
call(), apply(), bind()
this
Closure
function logString () {
var string = 'a';
console.log(string);
};
logString(); // a
console.log(string);
// Uncaught ReferenceError
// 'string' doesn't exist in global scope
var string;
string = 'a';
function logString () {
console.log(string);
};
logString(); // a
Scope ChainGlobal Vs. Function Scope
for (var i=0; i<3; i++) {
setTimeout(function() {
console.log(i);
}, 0);
}
// 3
// 3
// 3
function async (i) {
setTimeout(function() {
console.log(i);
}, 0);
};
for (var i=0; i<3; i++) {
async(i);
}
// 0
// 1
// 2
Calling function creates own scopeClosure is created
The nerdy stuff
Event Loop
Events
Callbacks
console.log('start');
setTimeout(function() {
console.log('hello from callback');
}, 0);
console.log('end');
// "start"
// "end"
// "hello from callback"
The sooo-nerdy stuff
Async
AJAX
JSONP / CORS
I'd have a
beer...
Event 💡
Sync 😢
Honey, bring
me a beer!!!
Async 🙌
Callback 😍
Neighboring Galaxies
Tag Management,
HTTP, DNS, SSL, Cookies,
HTML/DOM, Browsers, Console,
Local Storage, API, REST, jQuery
Web servers, Databases, Node.js, Mobile,
Linters, Package Managers, Bundlers, Task
Runners, Selenium, PhantomJS, CasperJS,
Charles Proxy, VCS, Babel, React,...
Don't try this at home
"use strict";
Prototypal inheritance
Promises
ECMAScript 6+
Immutable Stateless JS

JavaScript for Web Analysts