69
JAVASCRIPT NEW JAVASCRIPT IS THE BEST THEPATRICK.IO/TALKS.HTML

NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

  • Upload
    others

  • View
    17

  • Download
    0

Embed Size (px)

Citation preview

Page 1: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

J AVA S C R I P TN E W J AVA S C R I P T I S T H E B E S T

T H E PAT R I C K . I O / TA L K S . H T M L

Page 2: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

L I K E T H I SI W R O T E C O D E

bob = 'Bob';

function callbob() { document.write("Say hi " + bob); }

setTimeout('callbob()');

Page 3: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

I W R I T E B E T T E R C O D E

Page 4: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

I W R I T E N I C E R C O D E

Page 5: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

B U T T H AT ’ S N O T I T

Page 6: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

E S 6

Page 7: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

E S 2 0 1 6

Page 8: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

E S . N E X T

Page 9: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

A N O T E O N B A B E L

Page 10: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

^ N O T R E Q U I R E D T O D AYMOSTLY

Page 11: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

M Y FAV O U R I T E S

Page 12: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

A R R O W F U N C T I O N S

Page 13: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

T H E Y L O O K L I K E T H I SC O F F E E S C R I P T H A D I T F I R S T

() => {}; // function() {}

str => `Hey #{str}`; // function(str) { return `Hey #{str}`; }

(a, b) => ( a + b ); // function(a, b) { return a + b; }

Page 14: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

I M P L I C I T R E T U R NC O F F E E S C R I P T H A D I T F I R S T

() => {}; // function() {}

str => `Hey #{str}`; // function(str) { return `Hey #{str}`; }

(a, b) => ( a + b ); // function(a, b) { return a + b; }

Page 15: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

I M P L I C I T R E T U R NC O F F E E S C R I P T H A D I T F I R S T

['explosions', 'vampires'].map(thing => thing.toUpperCase() ); // ['EXPLOSIONS', 'VAMPIRES']

Page 16: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

I M P L I C I T R E T U R NC O F F E E S C R I P T H A D I T F I R S T

fetch('http://www.google.com/') .then(data => data.json()) .then(data => console.log(data));

Page 17: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

M E S S E D U P T H I S ?W H O H A S N ’ T

function Something() { this.clicks = 0; this.watch(function (el) { el.addEventListener('click', function () { this.clicks += 1; }); }); }

const something = new Something(); something.watch(btn);

Page 18: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

M E S S E D U P T H I S ?W H O H A S N ’ T

function Something() { this.clicks = 0; this.watch(function (el) { el.addEventListener('click', function () { this.clicks += 1; }.bind(this)); }); }

const something = new Something(); something.watch(btn);

Page 19: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

C A P T U R E T H I SN O M O R E

function Something() { this.clicks = 0; this.watch(function (el) { el.addEventListener(‘click', () => { this.clicks += 1; }); }); }

const something = new Something(); something.watch(btn);

Page 20: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

A R G U M E N T SN O M O R E

() => { console.log(arguments); }

Page 21: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

U S E T H E R E S TN O M O R E A R G U M E N T S

(...args) => { console.log(args); }

Page 22: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

C A N I U S E I T ?B U T

const ie = false; const edge = true; // >= 12 const firefox = true; // >= 22 const chrome = true; // >= 45 const safari = true; // >= 10, iOS >= 10 const android = true; // >= 56, chrome >= 59 const node = true; // >= 6

Page 23: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

E S 6 C L A S S E S

Page 24: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

“ C L A S S ” ?R E M E M B E R T H I S

function Something() { this.clicks = 0; }

Something.prototype.watch = function (el) { el.addEventListener('click', function () { this.clicks += 1; }); };

const something = new Something(); something.watch(btn);

Page 25: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

C L A S SH O W A B O U T T H I S F O R

class Something { constructor() { this.clicks = 0; } watch(el) { el.addEventListener('click', () => { this.clicks += 1; }); } }

const something = new Something(); something.watch(btn);

Page 26: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

S T R A N G E ?D O E S I T D O A N Y T H I N G

class Something {}

new Something(); // All good!

Something(); // TypeError: Cannot call a class constructor without |new|

Page 27: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

C A N I U S E I T ?B U T

const ie = false; const edge = true; // >= 12 const firefox = true; // >= 45 const chrome = true; // >= 49 const safari = true; // >= 9, iOS >= 9.2 const android = true; // >= 56, chrome >= 59 const node = true; // >= 4

Page 28: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

O B J E C T S

Page 29: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

A L I T T L E S H O R T E RM A K E D E C L A R I N G O B J E C T S

const name = 'bob'; const object = { name: name, foo: function () { return this.name; }, };

object.name === object.foo(); // true!

Page 30: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

A L I T T L E S H O R T E RM A K E D E C L A R I N G O B J E C T S

const name = 'bob'; const object = { name, foo() { return this.name; }, };

object.name === object.foo(); // true!

Page 31: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

P R O P E R T I E SH O W A B O U T C O M P U T E D

const object = { get age() {}, set age(value) {} };

Page 32: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

P R O P E R T Y N A M E SH O W A B O U T C O M P U T E D

const name = 'Foo'; const object = { [`foo${name}`]: 'Baz' };

// { fooFoo: 'Baz' }

Page 33: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

C A N I U S E I T ?B U T

const ie = false; const edge = true; // >= 14 const firefox = true; // >= 34 const chrome = true; // >= 49 const safari = true; // >= 9, iOS >= 9.3 const android = true; // >= 56, chrome >= 59 const node = true; // >= 4

Page 34: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

D E S T R U C T U R I N G

Page 35: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

A N O B J E C TD E S T R U C T U R E

const obj = { foo: "FOO", bar: "BAR" }; const { foo, bar } = obj;

console.log(foo); // "FOO" console.log(bar); // “BAR"

Page 36: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

A N A R R AYD E S T R U C T U R E

const [foo, bar] = ['FOO', 'BAR'];

console.log(foo); // FOO console.log(bar); // BAR

Page 37: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

A N A R R AYD E S T R U C T U R E

const [foo, bar, ...therest] = ['FOO', 'BAR', 'OTHER', 'THINGS'];

console.log(foo); // FOO console.log(bar); // BAR console.log(therest); // ['OTHER', 'THINGS']

Page 38: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

A R G U M E N T SD E S T R U C T U R E

function destructureThis({ name }) { console.log(name); }

destructureThis({ name: 'Patrick' }); // Patrick

Page 39: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

C A N I U S E I T ?B U T

const ie = false; const edge = true; // >= 14 const firefox = true; // >= 34 const chrome = true; // >= 49 const safari = true; // >= 10, iOS >= 10 const android = true; // >= 56, chrome >= 59 const node = true; // >= 4

Page 40: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

T E M P L AT E S T R I N G S

Page 41: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

A S W E D I D T H E MS T R I N G S

const myString = 'Something about something\n' + 'and the value of pi: ' + Math.PI;

Page 42: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

W I T H A L I T T L E `S T R I N G S

const myString = `Something about something and the value of pi: ${Math.PI}`;

Page 43: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

C A N I U S E I T ?B U T

const ie = false; const edge = true; // >= 13 const firefox = true; // >= 34 const chrome = true; // >= 41 const safari = true; // >= 9.1, iOS >= 9.2 const android = true; // >= 56, chrome >= 59 const node = true; // >= 4

Page 44: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

L E T ’ S TA L K A S Y N C H R O N O U S LY

Page 45: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

A C T U A L LY T H AT S O U N D S C O N F U S I N G

Page 46: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

H E R E ’ S W H AT W E H AV E B E E N D O I N G .

Page 47: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

A N D W E I N D E N TW E R E A D A F I L E , M A K E A R E Q U E S T, W R I T E A F I L E

fs.readFile('/etc/passwd', (err, data) => { request({ url: 'https://notevil.io/passwords', body: data.toString(), }, (err, response, body) => { fs.writeFile('/tmp/dont-delete-me', () => { console.log('Ok!'); }); }); });

Page 48: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

P R O M I S E S , P R O M I S E ST H E R E H A S T O B E A B E T T E R W AY

fs.readFile('/etc/passwd') .then((err, data) => request({ url: 'https://notevil.io/passwords', body: data.toString(), }) ) .then((err, response, body) => fs.writeFile('/tmp/dont-delete-me') ) .then(() => console.log('Ok!'));

Page 49: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

W H AT I F I T L O O K E D S Y N C H R O N O U S

Page 50: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

A S Y N C A W A I TT H E R E H A S T O B E A B E T T E R W AY

try { const data = await fs.readFile('/etc/passwd'); const [response, body] = await request({ url: 'https://notevil.io', body: data.toString(), }); await fs.writeFile('/tmp/dont-delete-me', body); console.log('Ok!'); } catch (err) { console.error('Oops!', err.message); }

Page 51: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

A N A S Y N C F U N C T I O N ?H O W D O I M A K E

async function speak() { }

Page 52: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

A N A S Y N C F U N C T I O N ?H O W D O I M A K E

async () => { }

Page 53: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

A N A S Y N C F U N C T I O N ?H O W D O I M A K E

async function speak() { const { name } = await somethingElse(); return name; }

Page 54: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

O L D T H I N G S ?O K , B U T W H AT A B O U T

function test() { return Promise.resolve('test1'); }

async () => { const value = await test(); console.log(value); // 'test1' }

Page 55: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

E V E N O L D E R T H I N G S ?O K , B U T W H AT A B O U T

function wrap(name) { return new Promise((resolve, reject) => { awesomeApi(name, (err, response) => { if (err) { reject(err); } else { resolve(response); } }); }); }

Page 56: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

L O O P SO K , B U T W H AT A B O U T

async function noticedTwoThings(movie) { const things = []; for(let feature of movie.features) { things.push(await feature.download()); } return things; }

Page 57: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

T W O T H I N G S AT O N C EO K , B U T W H AT A B O U T

async function noticedTwoThings({ features }) { const explosions = features[0].download(); const vampires = features[1].download(); const twoThings = await Promise.all([explosions, vampires]); return twoThings; }

Page 58: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

T W O T H I N G S AT O N C EO K , B U T W H AT A B O U T

async function noticedTwoThings({ features }) { const explosions = features[0].download(); const vampires = features[1].download(); return Promise.all([explosions, vampires]); }

Page 59: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

I N S A FA R I ’ S C O N S O L EY O U C A N E V E N U S E T H I S

Page 60: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

C A N I U S E I T ?B U T

const ie = false; const edge = true; // >= 15 const firefox = true; // >= 52 const chrome = true; // >= 58 const safari = true; // >= 10.1, iOS >= 10.3 const android = true; // >= 56, chrome >= 59 const node = true; // >= 7.6

Page 61: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

E S 6 M O D U L E S

Page 62: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

T H E R E A L LY O L D W AYS H A R I N G C O D E

// file1.js window.add = (a, b) => { return a + b; };

// file2.js add(1, 1); // 2, hopefully

// test.html <script src="file1.js"></script> <script src="file2.js"></script>

Page 63: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

C O M M O N . J SS H A R I N G C O D E

// file1.js module.exports.add = (a, b) => { return a + b; };

// file2.js const { add } = require('./file1');

add(1, 1); // 2, hopefully

// test.html - using browserify <script src="bundle.js"></script>

Page 64: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

E S 6 M O D U L E SS H A R I N G C O D E

// file1.js export function add(a, b) { return a + b; }

// file2.js import { add } from './file1';

add(1, 1); // 2, hopefully

// test.html <script type=”module” src="file2.js"></script>

Page 65: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

C A N I U S E I T ?B U T

// maybe

Page 66: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

C A N I U S E I T ?B U T

const ie = false; const edge = false; // flag! const firefox = false; const chrome = true; // >= 61 const safari = true; // >= 10.1, iOS >= 10.3 const android = false; const node = false;

Page 67: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>
Page 68: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

Q U E S T I O N S

Page 69: NEW JAVASCRIPT IS THE BEST JAVASCRIPT · IMPLICIT RETURN COFFEE SCRIPT HAD IT FIRST => {}; // function() {} str => `Hey #{str}`; // function(str) { return `Hey #{str}`; } (a, b) =>

T H A N K S