1 of 132

tt(fa)

2 of 132

outline

Total (80m)

  • html (3m)
  • css (2m)
  • markdown (2m)
  • bash (1m)
  • git (1m)
  • npm (1m)
  • node (70m)

3 of 132

JavaScript

recap

4 of 132

schedule

tomorrow

  • workshop env
  • partner

yesterday

  • kickoff
  • a fun exercise
  • partner pitch
  • explore the neighbourhood

previous

  • guest speakers
  • research

now

  • bootcamp

next

  • research & development

5 of 132

contents

  • html
  • css
  • markdown
  • bash
  • git
  • npm
  • js

6 of 132

html

  • structure
  • hypertext markup language
  • MDN reference and overview of features
  • HTML5 Doctor (useful overview of docs)

7 of 132

html

<!doctype html><html lang=nl><meta charset=utf8><title>Title</title><link rel=stylesheet href=index.css> <h1>Hello, world!</h1><!--Comment--> <script src=index.js></script>

8 of 132

html

<!doctype html><html lang=nl><meta charset=utf8><title>Title</title><link rel=stylesheet href=index.css><h1>Hello, world!</h1><!-- ...and hackers! --><script src=index.js></script>

Doctype

element

text

comment

9 of 132

html

<!doctype html><html lang=nl><meta charset=utf8><title>Title</title><link rel=stylesheet href=index.css><h1>Hello, world!</h1><!--Comment--><script src=index.js></script>

closing tag

opening tag

10 of 132

html

<!doctype html><html lang=nl><meta charset=utf8><title>Title</title><link rel=stylesheet href=index.css><h1>Hello, world!</h1><!--Comment--><script src=index.js></script>

void element

11 of 132

html

<!doctype html><html lang=nl><meta charset=utf8><title>Title</title><link rel=stylesheet href=index.css><h1>Hello, world!</h1><!--Comment--><script src=index.js></script>

attribute

name

value

12 of 132

css

  • presentation
  • cascading style sheets
  • MDN overview (with examples)
  • Interactive overview (with examples)

13 of 132

css

* { box-sizing: border-box }��html { font-family: Roboto /* … */ }��body {background-color: #fdfdfc;position: relative;max-width: 36rem;margin: 0 auto;padding: 2rem}

14 of 132

css

* { box-sizing: border-box }��html { font-family: Roboto /* … */ }��body { background-color: #fdfdfc;position: relative;max-width: 36rem;margin: 0 auto;padding: 2rem}

rule

selector

comment

15 of 132

css

* { box-sizing: border-box }��html { font-family: Roboto /* … */ }��body { background-color: #fdfdfc;position: relative;max-width: 36rem;margin: 0 auto;padding: 2rem}

declaration

property

value

16 of 132

markdown

17 of 132

markdown

# Heading��A normal paragraph��* An�* Unordered List��1. An�2. Ordered List

18 of 132

markdown

A paragraph��> a block quote��Another paragraph��```js�and.aBit({of: 'JavaScript'})```

19 of 132

markdown

A paragraph with *emphasis*, **importance**, and `inline.code()`.��A [link](https://example.com).��And an ![image](https://example.com/image.png).

20 of 132

markdown

21 of 132

bash

  • command language

22 of 132

bash

[~]$ rm -f foo.txt

23 of 132

bash

[~]$ rm -f foo.txt

prompt

24 of 132

bash

[~]$ rm -f foo.txt

command

25 of 132

bash

[~]$ rm -f foo.txt

options

26 of 132

bash

[~]$ rm -f foo.txt

arguments

27 of 132

bash

common programs

  • pwd navigate print working directory
  • ls navigate list directory contents
  • cd navigate change working directory
  • rm files remove
  • mv files move
  • cp files copy
  • less apps read
  • vim apps write
  • man apps read the manual
  • sudo rights do something as someone else

28 of 132

bash

bash

[examples] $ man cp

CP(1) BSD General Commands Manual CP(1)

NAME� cp -- copy files

SYNOPSIS� cp [-R [-H | -L | -P]] source target_file

cp [-R [-H | -L | -P]] source … target_directory

DESCRIPTION� In the first synopsis form, the cp utility copies� the contents of the source to the target_file.� In the second synopsis form, the contents of each� named source is copied to the destination� Target_directory. The names of the files� themselves are not changed. If cp detects an� attempt to copy a file to itself, the copy will� fail.

29 of 132

git

  • version control

30 of 132

git

common commands

  • git init create repository
  • git status show current state
  • git add file stage file
  • git commit store changes
  • git log show progress
  • git checkout -b branch create branch
  • git checkout branch switch to branch
  • git branch show branches
  • git merge branch apply changes
  • git branch -d branch remove branch

31 of 132

git

bash

[examples] $ git init

Initialized empty Git repository in /Users/tilde/projects/oss/examples/.git/

[examples] $ echo "Hello World!" > readme.md

[examples] $ git add --all

[examples] $ git commit --message "Add readme"

[master (root-commit) 0ee1887] Add readme� 1 file changed, 1 insertion(+)� create mode 100644 readme.md

this is Git

32 of 132

git

this is GitHub

33 of 132

npm

  • package manager

34 of 132

npm

common commands

  • npm init create package.json
  • npm install install saved dependencies
  • npm install package install and save dependency
  • npm run script run a script

35 of 132

npm

package.json

{"name": "camel-case","version": "3.0.0","description": "Camel case a string","license": "MIT","dependencies": {"no-case": "^2.2.0","upper-case": "^1.1.1",},/* … */}

36 of 132

js

  • programming language
  • ecmascript

Contents

  • core
  • environments
  • dom
  • node
  • es++
  • principles

37 of 132

js

core

Contents

  • types
  • operators
  • expressions
  • statements
  • functions

38 of 132

js

types - core

'this is text' // string42 // numbertrue // booleanfalse // booleanundefined // undefinednull // nullfunction () {} // function

['text', 1, false] // array{name: 'Cthulhu', age: 1337} // object

39 of 132

js

variables - core

var a

a // => undefined

a = 42

a // => 42

40 of 132

js

equality operators - core

a === b // Strict equality�a !== b // Strict inequality� a == b // Abstract equality� a != b // Abstract inequality

41 of 132

js

relational operators - core

a in b // has property�a instanceof b // instance of

a >= b // Greater than or equal to�a <= b // Smaller than or equal to�a > b // Greater than�a < b // Smaller than

42 of 132

js

update operators - core

++a // Increment, return new value� a++ // Increment, return old value++a // Decrement, return new value� a++ // Decrement, return old value

43 of 132

js

arithmetic operators - core

a + b // Addition�a - b // Subtraction�a * b // Multiplication�a / b // Division�a % b // Remainder after division-a // Negate

44 of 132

js

assignment operators - core

a = b // Assignment�a += b // Assignment and addition�a -= b // …�a *= b // …�a /= b // …�a %= b // …

45 of 132

js

logical operators - core

a && b // And�a || b // Or!a // Not

46 of 132

js

typeof operators - core

typeof 'this is text' // 'string'typeof 42 // 'number'typeof true // 'boolean'typeof false // 'boolean'typeof undefined // 'undefined'typeof null // 'object' (WTF?)typeof function () {} // 'function'

typeof [] // 'object' (WTF?)typeof {} // 'object'

47 of 132

js

conditional operators - core

a ? b : c // Conditional

48 of 132

js

expressions - core

a = b * 2

49 of 132

js

expressions - core

a = b * 2

variables

operators

literal values

50 of 132

js

expressions - core

a = b * 2�a = b * 2�a = b * 2a = b * 2

literal value expression

variable expression

arithmetic expression

assignment expression

51 of 132

js

statements - core

a = b * 2�a = b * 2�a = b * 2�a = b * 2

statement

52 of 132

js

if statements - core

var popsicles = 0��if (popsicles === 0) {popsicles++ // eat a popsicle}

53 of 132

js

if statements - core

var popsicles = 0��if (popsicles === 0) {� popsicles++ // eat a popsicle}

condition

54 of 132

js

else statements - core

var popsicles = 1��if (popsicles === 0) {� popsicles++ // eat a popsicle} else {

// no more ice cream please!}

55 of 132

js

else if statements - core

var popsicles = 1, coffee = 0��if (popsicles === 0) {� popsicles++ // eat a popsicle} else if (coffee === 1) {� coffee++ // drink a cup ’o joe} else { // no more ice cream or coffee please!}

56 of 132

js

while statements - core

var coffee = 1��while (coffee < 5) {� coffee++ // drink a cup ’o joe}

coffee //=> 5

57 of 132

js

while statements - core

var coffee = 1��while (coffee < 5) {� coffee++ // drink a cup ’o joe}

coffee //=> 5

condition

58 of 132

js

while statements - core

var coffee = 1��while (coffee > 0) {� coffee++ // drink a cup ’o joe}

coffee //=> ?

59 of 132

js

while statements - core

var coffee = 1��while (coffee > 0) {� coffee++ // drink a cup ’o joe}

coffee //=> ?

60 of 132

js

while statements - core

var coffee = 1��while (coffee > 0) {� coffee++ // drink a cup ’o joe}

coffee //=> ?

61 of 132

js

while statements - core

var coffee = 1��while (coffee > 0) {� coffee++ // drink a cup ’o joe}

coffee //=> ?

62 of 132

js

js

while statements - core

var coffee = 1��while (coffee > 0) {� coffee++ // drink a cup ’o joe}

coffee //=> ?

63 of 132

js

while statements - core

var coffee = 1��while (coffee > 0) {� coffee++ // drink a cup ’o joe}

coffee //=> ?

64 of 132

js

while statements - core

var names = ['Anna', 'Bisma', 'Chun']var i = 0��while (i < names.length) {� console.log(i, names[i])

i++}// 0, 'Anna'// 1, 'Bisma'// 2, 'Chun'

65 of 132

js

for statements - core

var names = ['Anna', 'Bisma', 'Chun']var i = 0��for (; i < names.length; ) {� console.log(i, names[i])

i++}// 0, 'Anna'// 1, 'Bisma'// 2, 'Chun'

66 of 132

js

for statements - core

var names = ['Anna', 'Bisma', 'Chun']var i = 0��for (; i < names.length; ) {� console.log(i, names[i])

i++}// 0, 'Anna'// 1, 'Bisma'// 2, 'Chun'

condition

67 of 132

js

for statements - core

var names = ['Anna', 'Bisma', 'Chun']for (var i = 0; i < names.length; ) {� console.log(i, names[i])

i++}// 0, 'Anna'// 1, 'Bisma'// 2, 'Chun'

68 of 132

js

for statements - core

var names = ['Anna', 'Bisma', 'Chun']for (var i = 0; i < names.length; ) {� console.log(i, names[i])

i++}// 0, 'Anna'// 1, 'Bisma'// 2, 'Chun'

before loop

69 of 132

js

for statements - core

var names = ['Anna', 'Bisma', 'Chun']for (var i = 0; i < names.length; i++) {� console.log(i, names[i])}// 0, 'Anna'// 1, 'Bisma'// 2, 'Chun'

70 of 132

js

for statements - core

var names = ['Anna', 'Bisma', 'Chun']for (var i = 0; i < names.length; i++) {� console.log(i, names[i])}// 0, 'Anna'// 1, 'Bisma'// 2, 'Chun'

after each iteration

71 of 132

js

for statements - core

var monster = {name: 'Ctulhu', age: 1337}var key��for (key in monster) {� console.log(key, monster[key])}// 'name', 'Ctulhu'// 'age', 1337

72 of 132

js

function statements - core

function sum(a, b) {return a + b�}��sum(2, 3) //=> 5

73 of 132

js

function hoisting - core

sum(2, 3) //=> 5

function sum(a, b) {return a + b�}

74 of 132

js

function expressions - core

var subtract = function (a, b) {return a - b�}��subtract(2, 3) //=> -1

75 of 132

js

function expressions - core

subtract(2, 3)

// [TypeError: subtract is not a function]

var subtract = function (a, b) {return a - b�}��

76 of 132

js

function scope - core

var a = 1��calculate()// 3��function calculate() {var b = 2� console.log(a + b)}

77 of 132

js

function scope - core

var a = 1��calculate()�console.log(a + b)// [ReferenceError: Can't find variable: b]��function calculate() {var b = 2}

78 of 132

js

callback function- core

a()�setTimeout(b, 4)�c()��function a() { console.log('a') }function b() { console.log('b') }function c() { console.log('c') }

79 of 132

js

environments

JavaScript the languages gives you:

  • Primitives: String ('a'), Number (1), Boolean (true), null, undefined
  • Objects: Array (['b', 2, false]), Object ({key: 'value'})
  • Functions (function hello(name) { return 'Hello ' + name })
  • Operators: Add (+), multiply (*), and (&&), ternary (x ? y : z),
  • Statements: Control flow (if (x) { … }), loops (while (y) { … }),

80 of 132

js

environments

JavaScript has some useful built-ins (that’s called a standard library):

  • Math (Math.round, Math.random, …)
  • Date (new Date, Date.now, …)
  • JSON (JSON.parse and JSON.stringify)

81 of 132

js

environments

In the Browser you get JS and…

  • console (console.log, …)
  • timers (setTimeout, …)
  • window
  • document (dom)
  • fetch (or xmlhttprequest)
  • <script>
  • canvas / webgl

In Node.js you get JS and…

  • console (console.log, …)
  • timers (setTimeout, …)
  • global
  • file system (fs)
  • http
  • require / module
  • buffer

82 of 132

js

browser

Contents

  • style
  • classList
  • queries
  • textContent / innerHTML
  • addEventListener / removeEventListener

83 of 132

js

dev tools - browser

84 of 132

js

style - dom - browser

document� .body� .style� .backgroundColor = 'red'

85 of 132

js

classlist - dom - browser

document� .body� .classList� .add('dark')

/* index.css */.dark {background-color: black;color: white�}

86 of 132

js

queries - dom - browser

document� .querySelector('h1').classList

.add('dark')

/* index.css */.dark {background-color: black;color: white�}

87 of 132

js

queries - dom - browser

var nodes = document� .querySelectorAll(':first-child')��console.log(nodes)

88 of 132

js

textcontent - dom - browser

document� .querySelector('h1')� .textContent = 'Hi!'

89 of 132

js

innerhtml - dom - browser

document� .querySelector('h1')� .innerHTML = '<a href=example.com>!!</a>'

90 of 132

js

innerhtml - dom - browser

var body = document.body�var count = 0��body.addEventListener('click', onclick)��function onclick() {� alert(count)if (++count > 5) {� body.removeEventListener('click', onclick)}}

91 of 132

js

node

Contents

  • buffer
  • fs
  • commonjs

92 of 132

js

buffer - node

bash

[examples] $ node

var buf = Buffer.from([0x74, 0xc3, 0xa9, 0x73, 0x74])��console.log(buf) //=> <Buffer 74 c3 a9 73 74>�console.log(buf.toString('ascii')) //=> 'tC)st'

console.log(buf.toString('utf8')) //=> 'tést'�console.log(buf.toString()) //=> 'tést'

93 of 132

js

fs - node

bash

[examples] $ node

fs.readFile('missing.html', onfile)��function onfile(err, buf) {if (err) throw err� console.log(buf)}

// [Error: ENOENT: no such file or directory, open 'missing.html']

94 of 132

js

fs - node

bash

[examples] $ node

fs.readFile('index.html', onfile)��function onfile(err, buf) {if (err) throw err� console.log(buf)}

// <Buffer 3c 21 64 6f 63 74 79 70 65 20 68 74 6d 6c 3e 0a 3c 68 74 6d 6c 20 6c 61 6e 67 3d 6e 6c 3e 0a ... >

95 of 132

js

fs - node

bash

[examples] $ node

fs.readdir('.', ondir)��function ondir(err, files) {if (err) throw err� console.log(files)}// ['index.css', 'index.html', 'index.js']

96 of 132

js

fs - node

bash

[examples] $ node

fs.writeFile('message.txt', 'Hello World!', onfile)��function onfile(err) {if (err) throw err� console.log('Saved!')}// Saved!

97 of 132

js

fs - node

bash

[examples] $ node

var stream = fs.createWriteStream('message.txt')��stream.write('Hello')�setTimeout(tick, 1000)��function tick() {� stream.write(' Streams!')� stream.end()}

98 of 132

js

commonjs - node

// index.js�console.log(sum(1, 2, 3))��function sum() {var total = 0var i = -1while (++i < arguments.length) {� total += arguments[i]}return total�}

99 of 132

js

commonjs - node

// index.jsvar sum = require('./sum.js')��console.log(sum(1, 2, 3))

// sum.js�module.exports = sum��function sum() {var total = 0var i = -1while (++i < arguments.length) {� total += arguments[i]}return total�}

100 of 132

js

es++

Contents

  • let / const
  • spread / rest
  • defaults
  • destructuring
  • concise
  • template literals
  • arrow functions
  • modules
  • promise

101 of 132

js

let and const - es++

for (var coffee = 0; coffee < 3; coffee++) {� console.log('Another coffee!', coffee)}// 'Another coffee', 0

// 'Another coffee', 1

// 'Another coffee', 2

�console.log('I drank ' + coffee + ' coffees')

// I drank 3 coffees

102 of 132

js

let and const - es++

for (let coffee = 0; coffee < 3; coffee++) {� console.log('Another coffee!', coffee)}// 'Another coffee', 0

// 'Another coffee', 1

// 'Another coffee', 2

�console.log('I drank ' + coffee + ' coffees')

// [ReferenceError: coffee is not defined]

103 of 132

js

let and const - es++

const coffee = 1

console.log('A coffee!', coffee)// 'A coffee', 1

coffee++// [TypeError: Attempted to assign to readonly property.]

104 of 132

js

spread and rest - es++

var place = [52.31, 4.95]��print(place)// [52.31, 4.95], undefined��function print(lat, lng) {� console.log(lat, lng)}

105 of 132

js

spread and rest - es++

var place = [52.31, 4.95]��print(place[0], place[1])// 52.31, 4.95��function print(lat, lng) {� console.log(lat, lng)}

106 of 132

js

spread and rest - es++

var place = [52.31, 4.95]��print(...place)// 52.31, 4.95��function print(lat, lng) {� console.log(lat, lng)}

107 of 132

js

spread and rest - es++

print(52.31, 4.95)// '52.31x4.95'��function print(...location) {� console.log(location.join('x'))}

108 of 132

js

defaults - es++

var lat = 52.31var lng = 4.95��print() // '0x0'�print(lat) // '52.31x0'�print(lat, lng) // '52.31x4.95'��function print(lat = 0, lng = 0) {� console.log(lat + 'x' + lng)}

109 of 132

js

destructuring - es++

var monster = {name: 'Ctulhu', age: 1337}��hello(monster) // Hello, Ctulhu!��function hello({name}) {� console.log('Hello, ' + name + '!')}

110 of 132

js

destructuring - es++

var place = [52.31, 4.95]��print(place)// '52.31x4.95'��function print([lat, lng]) {� console.log(lat + 'x' + lng)}

111 of 132

js

concise - es++

var name = 'Ctulhu'var age = 1337��var monster = {name, age}��console.log(monster) // {name: 'Ctulhu', age: 1337}

112 of 132

js

concise - es++

var age = 1337var monster = {� name: 'Ctulhu',� age,� greet() {return 'Hello, ' + this.name + '!'}}��console.log(monster.greet()) // 'Hello, Ctulhu!'

113 of 132

js

template literals - es++

var monster = {name: 'Ctulhu', age: 1337}��console.log(

`Hello, ${monster.name},you ${monster.age > 18 ? 'can' : 'can’t'} enter!`

)// 'Hello, Ctulhu,\nyou can enter!'

114 of 132

js

arrow functions - es++

var constant = () => 3var negative = a => -a�var sum = (a, b) => a + b�var subtract = (a, b) => { result = a - b; return result }

console.log(constant()) // 3�console.log(negative(1)) // -1�console.log(sum(1, 2)) // 3�console.log(subtract(1, 2)) // -1

115 of 132

js

arrow functions - es++

var monster = {� name: 'Ctulhu',� delayed() {� setTimeout(function () { console.log('Hi ' + this.name) }, 100)}}��monster.delayed()// 'Hi undefined'

116 of 132

js

arrow functions - es++

var monster = {� name: 'Ctulhu',� delayed() {� setTimeout(() => console.log('Hi ' + this.name), 100)}}��monster.delayed()// 'Hi Ctulhu'

117 of 132

js

modules - es++

// index.js�console.log(sum(1, 2, 3))��function sum(...values) {return values.reduce(add, 0)}

function add(acc, value) {return acc + value�}

118 of 132

js

modules - es++

// index.mjsimport sum from './sum.mjs'��console.log(sum(1, 2, 3))

// sum.mjsexport default function sum(...data) {return data.reduce(plus, 0)}

function plus(acc, value) {return acc + value�}

119 of 132

js

modules - es++

// index.mjsimport {sum} from './math.mjs'��console.log(sum(1, 2, 3))

// math.mjsexport function sum(...data) {return data.reduce(plus, 0)}

function plus(acc, value) {return acc + value�}

120 of 132

js

modules - es++

// index.mjsimport {subtract} from './math.mjs'��console.log(subtract(3, 2, 1))

// math.mjsexport function sum(...data) {

return data.reduce(plus, 0)}

export function subtract(...data) {return data.reduce(min, 0)}

function plus(acc, value) {return acc + value�}function min(acc, value) {return acc - value�}

121 of 132

js

promises - es++

import {req} from './req.mjs'��req('https://www.google.com', cb)��function cb(err, res) {if (err) console.error('offline')else console.log('online')}

// online

// req.mjsexport function req(url, cb) {// Make network request and call// cb on success or error}

122 of 132

js

promises - es++

fetch('https://www.google.com').then(function (res) {� console.log('online')}, function (err) {� console.log('offline')})

// online

123 of 132

js

promises - es++

fetch('https://www.google.com').then(function (res) {� console.log('online')}).catch(function (err) {� console.log('offline')})

// online

124 of 132

js

promises - es++

fetch('https://www.google.com').then(function (res) {return res.text()}).then(function (doc) {� console.log(doc)}).catch(function (err) {� console.log('offline')})// '<!doctype html><html lang="en-NL"><head><meta content="width=dev…'

125 of 132

js

promises - es++

console.log('a')�sleep(100).then(() => console.log('b'))�console.log('c')��function sleep(ms) {return new Promise(resolve => setTimeout(resolve, ms))}

126 of 132

js

principles

Contents

  • callbacks
  • events
  • streams
  • modules
  • async

127 of 132

callbacks

js

principles

128 of 132

events

js

principles

129 of 132

streams

js

principles

130 of 132

modules

js

principles

131 of 132

async

js

principles

132 of 132

schedule

yesterday

  • kickoff
  • a fun exercise
  • partner pitch
  • explore the neighbourhood

previous

  • guest speakers
  • research

now

  • bootcamp

next

  • research & development

tomorrow

  • workshop env
  • partner