+ - 0:00:00
Notes for current slide
Notes for next slide

Intro to "Modern" JavaScript

1 / 21

Agenda

  • Brief History
  • Overview
  • Ecosystem
  • Features
2 / 21

Brief History

  • 1995
    • Netscape recruited Breadan Eich to create:
      • a Java young brother
      • written directly in the HTML
      • prototype made in 10 days
3 / 21

Brief History

  • 1995
    • Netscape recruited Breadan Eich to create:
      • a Java young brother
      • written directly in the HTML
      • prototype made in 10 days
  • 1996
    • Nestscape submitted Javascript to Ecma International
      • former European Computer Manufacturers Association
  • 1997: EcmaScript 1
  • 1998: EcmaScript 2
  • 1999: EcmaScript 3
  • ????: EcmaScript 4
3 / 21

Brief History

  • 1995
    • Netscape recruited Breadan Eich to create:
      • a Java young brother
      • written directly in the HTML
      • prototype made in 10 days
  • 1996
    • Nestscape submitted Javascript to Ecma International
      • former European Computer Manufacturers Association
  • 1997: EcmaScript 1
  • 1998: EcmaScript 2
  • 1999: EcmaScript 3
  • ????: EcmaScript 4
  • 2009: EcmaScript 5 (Harmony)
  • 2011: EcmaScript 5.1
3 / 21

Brief History

  • 1995
    • Netscape recruited Breadan Eich to create:
      • a Java young brother
      • written directly in the HTML
      • prototype made in 10 days
  • 1996
    • Nestscape submitted Javascript to Ecma International
      • former European Computer Manufacturers Association
  • 1997: EcmaScript 1
  • 1998: EcmaScript 2
  • 1999: EcmaScript 3
  • ????: EcmaScript 4
  • 2009: EcmaScript 5 (Harmony)
  • 2011: EcmaScript 5.1
  • 2015: EcmaScript 2015
  • 2016: EcmaScript 2016
  • 2017: EcmaScript 2017

ECMAScript proposals

3 / 21

Ecma examples of specifications: CD-ROM, Office Open XML, JSON

Overview

  • (Usually) Interpreted
  • Dynamic typing
    • type checking at run time
  • Weakly typed
    • operations without defined types for the operands in question
    • implicit type conversions
"10" + 1 // "101"
"10" / 1 // 10
  • Prototype Based
4 / 21

Weakly typed: implicit type conversions

Ecosystem

5 / 21

Ecosystem

5 / 21

Ecosystem

5 / 21

Ecosystem

5 / 21

Ecosystem

5 / 21

Ecosystem

5 / 21

Language

  • Declaring constants/variables
  • Data types
  • Declaring functions
  • Passing functions as argument
  • Using Object and Arrays
  • Handling Promises
6 / 21

Playground

7 / 21

Code Structure

alert('Hello'); alert('World');
// Hello World
alert('Hello')
alert('World')
/* Hello World */
8 / 21

Constants and variables

let name
name = 'Tomato'
name = 'Tomato'
const name2 = 'Potato'
9 / 21

Data types

let a // undefined
a = null
a = 2
a = '2'
a = true
alert(typeof a) // "boolean"
10 / 21

Arrays

const animals = ['Giraffe', 'Cat', 22]
11 / 21

Arrays

const animals = ['Giraffe', 'Cat', 22]
alert(animals[1]) // 'Cat'
11 / 21

Arrays

const animals = ['Giraffe', 'Cat', 22]
alert(animals[1]) // 'Cat'
Array.isArray('blah') // false
animals.push('Dog')

MDN - Array

11 / 21

Objects

const logins = {
test: 'test123',
admin: 'admin'
}
12 / 21

Objects

const logins = {
test: 'test123',
admin: 'admin'
}
logins.test // 'test123'
logins['admin']
logins.user = 'changeme'
12 / 21

Objects

const logins = {
test: 'test123',
admin: 'admin'
}
logins.test // 'test123'
logins['admin']
logins.user = 'changeme'
Object.keys(logins) // ['test', 'admin', 'user']
logins.hasOwnProperty('root') // false

MDN - Object

12 / 21

Conditionals

if

let year = prompt('In which year was ECMAScript-2015 specification published?', '');
if (year < 2015) {
alert( 'Too early...' )
} else if (year > 2015) {
alert( 'Too late' )
} else {
alert( 'Exactly!' )
}
13 / 21

Conditionals

if

let year = prompt('In which year was ECMAScript-2015 specification published?', '');
if (year < 2015) {
alert( 'Too early...' )
} else if (year > 2015) {
alert( 'Too late' )
} else {
alert( 'Exactly!' )
}

0, an empty string "", null, undefined and NaN become false (falsy values)

13 / 21

Ternary operator

let accessAllowed = (age > 18) ? 'content' : 'nope'
14 / 21

Ternary operator

let accessAllowed = (age > 18) ? 'content' : 'nope'
let accessAllowed = age > 18
? 'content'
: 'nope'
14 / 21

Declaring functions

function sum (a, b) {
return a + b
}
15 / 21

Declaring functions

function sum (a, b) {
return a + b
}
const sum = (a, b) => {
return a + b
}
15 / 21

Declaring functions

function sum (a, b) {
return a + b
}
const sum = (a, b) => {
return a + b
}
const sum = (a, b) => a + b
15 / 21

Functions as arguments

const print = (operation, a, b) => {
const result = operation(a, b)
alert(result)
}
16 / 21

Functions as arguments

const print = (operation, a, b) => {
const result = operation(a, b)
alert(result)
}
print(sum, 1, 2)
16 / 21

Functions as arguments

const print = (operation, a, b) => {
const result = operation(a, b)
alert(result)
}
print(sum, 1, 2)
print((a, b) => a + b, 1, 2)
16 / 21

Functions as arguments - forEach

[1,2,3,4].forEach(alert)
17 / 21

Functions as arguments - forEach

[1,2,3,4].forEach(alert)
[1,2,3,4].forEach((a) => {
alert(a + 2)
})
17 / 21

Callbacks

18 / 21

Callbacks

const alertTest = alert('test')
setTimeout(alertTest, 100)
18 / 21

Callbacks

const alertTest = alert('test')
setTimeout(alertTest, 100)
const button = document.getElementById('load-button')
const hello = function (event) {
alert('clicked')
}
button.addEventListener("click", hello)
18 / 21

Promises

new Promise((resolve, reject) => {
})
19 / 21

Promises

new Promise((resolve, reject) => {
})
const letsParty = () => {
return new Promise((resolve, reject) => {
Date.now().getDay() !== 6
? reject()
: setTimeout(resolve, 100)
}
})
19 / 21

Promises

new Promise((resolve, reject) => {
})
const letsParty = () => {
return new Promise((resolve, reject) => {
Date.now().getDay() !== 6
? reject()
: setTimeout(resolve, 100)
}
})
letsParty().then(() => {
// ...
})
19 / 21

Promises

new Promise((resolve, reject) => {
})
const letsParty = () => {
return new Promise((resolve, reject) => {
Date.now().getDay() !== 6
? reject()
: setTimeout(resolve, 100)
}
})
letsParty().then(() => {
// ...
})
letsParty().then((response) => {
// ...
}).catch((error) => {
// ...
})
19 / 21

Agenda

  • Brief History
  • Overview
  • Ecosystem
  • Features
2 / 21
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow