javascript for python developers · typescript. overview ... js for python developers -- europython...

49
JavaScript for Python Developers EuroPython 26th July, 2018 Žan Anderle Twitter: @z_anderle

Upload: others

Post on 30-Dec-2020

45 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

JavaScript for Python Developers

EuroPython26th July, 2018

Žan Anderle Twitter: @z_anderle

Page 2: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Raise your hand if…

Page 3: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

JavaScript and Python developers

Page 4: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

https://hackernoon.com/how-it-feels-to-learn-javascript-in-2016-d3a717dd577f

Page 5: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM
Page 6: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM
Page 7: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Overview

• JavaScript history and versions

• Basics of the language

• JavaScript ecosystem

• How to make sense of it all?

Page 8: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM
Page 9: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Overview

• JavaScript history and versions

• Basics of the language

• Different tools

• How to make sense of it all?

Page 10: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM
Page 11: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Overview

• JavaScript history and versions

• Basics of the language

• Different tools

• How to make sense of it all?

Page 12: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Syntaxlet myName = 'EuroPython 2018'; function sayHi(name) { console.log(`Hey there, ${name}`); }

sayHi(myName); // 'Hey there, EuroPython 2018';

let someArray = [1, 2, 5, 10]; let newArray = [];

for (let el of someArray) { if (el > 2) { newArray.push(el); } else { console.log('Nope!'); } } // 'Nope!' // 'Nope!'

Page 13: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Syntaxclass Hero { constructor(name, superPower) { this.name = name; this.superPower = superPower; }

superPower() { console.log('I can count really fast!'); let count = 0; while (count < 1000) { count++; } return count; } }

let superMan = new Hero('SuperMan');

superMan.superPower(); // 'I can count really fast!' // 1001

Page 14: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Syntax

let x = 1; // x is a number x = 'Hi!'; // x is now a string x = () => { return 1; }; // x is now a function

Page 15: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Syntax

Page 16: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Variables

var x = 1; let name = 'John'; const someConstant = 45;

Page 17: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Variable hoisting

var x = 1;

// Some other code

var name = 'John';

var x; var name; x = 1;

// Some other code

name = 'John';

Page 18: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Variable hoisting

var txt = ["a","b","c"];

for (var i = 0; i < 3; ++i ) { var msg = txt[i]; setTimeout(function() { alert(msg); }, i*1000); }

// Alerts 'c', 'c', 'c'

Page 19: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Data Types• Boolean

• String

• Number

• Null

• Undefined

• Object

let a = true; let b = false;

let name = 'John'; name.length; // 4

let num = -124.56; num = 10;

let empty = null; let unknown = undefined;

let something = {key: 'A value', anotherKey: name}; let things = ['string', 2, (x, y) => { return x + y; }];

Page 20: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Object literal

let bigObj = { key: 'Some string', add: function(x, y) { return x + y; }, anotherObj: { name: 'I am a nested object' } };

Page 21: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Objects are mutable

Page 22: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Operators

if (!a && b) { // Some code } else if (a || b) { // Some code }

Page 23: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Operators

== and !=

OR

=== and !==

Page 24: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Operators

Page 25: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Functions

let func = function(a, b) { return a + b; };

let func = (a, b) => { return a + b; }; let func = (a, b) => a + b;

Page 26: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Functions

function func(a = 1, b = 2) { return a + b; }

func(5); // 7

Page 27: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Functions

function func(a = 1, b = 2) { // Do some calculations }

func(5); // undefined

Page 28: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

this

Page 29: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

this

Page 30: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

this

Page 31: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Classes

Page 32: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Modules

Page 33: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Template literals

var a = 5; var b = 10; console.log(`Fifteen is ${a + b} and not ${2 * a + b}.`); // "Fifteen is 15 and // not 20."

Page 34: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Template literals

let a = 5; let b = 10; console.log('Fifteen is ' + (a + b) + ' and\nnot ' + (2 * a + b) + '.'); // "Fifteen is 15 and // not 20."

Page 35: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Promises

Page 36: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Overview

• JavaScript history and versions

• Basics of the language

• Different tools

• How to make sense of it all?

Page 37: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Bad Parts

• Global variables

• ==

• +

• scope

Page 38: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

TypeScript

Page 39: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Overview

• JavaScript history and versions

• Basics of the language

• Different tools

• How to make sense of it all?

Page 40: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Different tools

• npm, bower, yarn

• Babel

• Webpack

• gulp, grunt

Page 41: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Different tools

• npm, bower, yarn

• Babel

• Webpack

• gulp, grunt

Page 42: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Different tools

• npm, bower, yarn

• Babel

• Webpack

• gulp, grunt

Page 43: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Different tools

• npm, bower, yarn

• Babel

• Webpack

• gulp, grunt

Page 44: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Different tools

• npm, bower, yarn

• Babel

• Webpack

• gulp, grunt

Page 45: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM
Page 46: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Overview

• JavaScript history and versions

• Basics of the language

• Different tools

• How to make sense of it all?

Page 47: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

How to get started

• Start somewhere

• Prepare your codebase

• No need to learn and use everything at once

Page 48: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM
Page 49: JavaScript for Python Developers · TypeScript. Overview ... JS for Python developers -- EuroPython 2018 Created Date: 7/27/2018 9:35:20 AM

Thank you! Questions?