SlideShare a Scribd company logo
1 of 50
Download to read offline
#TechDaysNL
@rickbeerendonk
JavaScript for C# Developers
Rick Beerendonk
rick@oblicum.com
Training: rick@oblicum.com or @rickbeerendonk
• ECMAScript
• 5, 2015, 2016, 2017…
• React
• Components, Properties, State, Events, Virtual DOM…
• Redux
• Actions, Reducers, Stores…
• Samples & Slides
• https://github.com/rickbeerendonk/ECMAScript-2015-2017-Demos

Quiz
ECMAScript 2016
JavaScript
🙋 🙎
1. The following code is…
var x = 10;
🙋 C#
🙎 JavaScript
1. The following code is…
var x = 10;
🙋 C# 🎉
🙎 JavaScript 🎉
2. C#’s foreach in JavaScript is…
🙋 for .. in
🙎 for .. of
2. C#’s foreach in JavaScript is…
🙋 for .. in
🙎 for .. of 🎉
3. Indeterminate Number of Parameters in JavaScript
C#: void Test(params int[] a)
🙋 function test([]a)
🙎 function test(…a)
3. Indeterminate Number of Parameters in JavaScript
C#: void Test(params int[] a)
🙋 function test([]a)
🙎 function test(…a) 🎉
4. When does calling this function throw an error?
function test(a, b)
1finger🙋 test(1)
2fingers🙋 test(1, 2)
3fingers🙋 test(1, 2, 3)
🙎 <never>
4. When does calling this function throw an error?
function test(a, b)
1finger🙋 test(1)
2fingers🙋 test(1, 2)
3fingers🙋 test(1, 2, 3)
🙎 <never> 🎉
5. Call constructor of the parent class
class Child extends Parent {
constructor(name, value) {
<???>
this.balance = value;
}
}
🙋 base(name)
🙎 super(name)
5. Call constructor of the parent class
class Child extends Parent {
constructor(name, value) {
<???>
this.balance = value;
}
}
🙋 base(name)
🙎 super(name) 🎉
• 2009: 5th Edition
• 2015: 6th Edition
• Changed to:
‣ Yearly releases (in June)
‣ Year = version number
ECMAScript
• Finished proposals
• Active proposals
Ecma International, Technical Committee 39 (TC39)
• String
• Number
• Bool
• Undefined
• Null
Primitive Data Types
• String
‣ Single ('') or Double Quotes ("")
‣ C#: Char & String
• Number
‣ C#: Double & Int
• Bool
• Undefined
• Null
Primitive Data Types
Variable declarations
var a = 1;
if (true) {
var a = 2;
console.log(a); // 2
}
console.log(a); // 2
let a = 1;
if (true) {
let a = 2;
console.log(a); // 2
}
console.log(a); // 1
C# var scoping = JS let scoping
Constants
var a = 1;
if (true) {
var a = 2;
console.log(a); // 2
}
console.log(a); // 2
// unchangeable
const a = 1;
if (true) {
const a = 2;
console.log(a); // 2
}
console.log(a); // 1
Same as C#
var name = "EcmaScript";
var version = 2015;
Func<string> x = () => "hi!";
var result = $"This is about:
{name} {version + 1} {x()}";
Console.WriteLine(result);
// This is about:
// EcmaScript 2016 hi!
Template Strings C#
var name = "EcmaScript";
var version = 2015;
var x = () => "hi!";
var result = $"This is about:
{name} {version + 1} {x()}";
console.log(result);
// This is about:
// EcmaScript 2016 hi!
Template Strings
var name = "EcmaScript";
var version = 2015;
var x = () => "hi!";
var result = `This is about:
${name} ${version + 1} ${x()}`;
console.log(result);
// This is about:
// EcmaScript 2016 hi!
Template Strings JavaScript
C# $"{}" = JS `${}`
console.log('0'.padStart(3)); // ' 0'
console.log('000'.padStart(1, '1')); // 000
console.log('000'.padStart(3, '1')); // 000
console.log('000'.padStart(5, '1')); // 11000
console.log('000'.padStart(5, '123')); // 12000
console.log('000'.padStart(7, '123')); // 1231000
String Padding (ES2017)
C# String.PadLeft() = JS String.padStart()
console.log('0'.padEnd(3)); // '0 '
console.log('000'.padEnd(1, '1')); // 000
console.log('000'.padEnd(3, '1')); // 000
console.log('000'.padEnd(5, '1')); // 00011
console.log('000'.padEnd(5, '123')); // 00012
console.log('000'.padEnd(7, '123')); // 0001231
String Padding (ES2017)
C# String.PadRight() = JS String.padEnd()
Equality: == vs ===
let i = 1;
let s = '1';
console.log(i == s);
// true (value)
C# == is the same as JS ===
let i = 1;
let s = '1';
console.log(i === s);
// false (value + type)
• If
‣ if (true || false) {

console.log('positive');

} else { 

console.log('negative');

}
• Inline
‣ console.log(true || false ? 'positive' : 'negative');
Conditional Statements
Same as C#
• for
‣ for (let i = 0; i < 2; i++) { console.log(i)}
• forEach
‣ [1, 2, 3].forEach((element, index, array) =>
console.log(`a[${index}] = ${element}`))
• for .. in
‣ Iterates over object properties
• for .. of
‣ Iterates over iterable object (Array, String, Map, Set, etc.)
Loops
C# for = JS for C# foreach = JS for .. of
let test = {
[Symbol.iterator]: function*() {
let current = 1;
while (true) {
yield current++;
}
}
}
Generators / Iterators
C# function + yield + foreach = JS function* + yield + for .. of
for (var n of test) {
if (n > 10) {
break;
}
console.log(n);
}C# IEnumerable = JS Iterator
function test(a, b) {
console.log(a);
console.log(b);
}
test(1); // a = 1, b = undefined
test(1, 2, 3, 4); // a = 1, b = 2, 3 = ignored
Functions: Overloads
C# overload = JS one function
function test(a = 11, b = '22') {
console.log(a);
console.log(b);
}
test(); // a = 11, b = '22'
test(1, 2, 3, 4); // a = 1, b = 2, 3 & 4 = ignored
Functions: Default parameters
C# = JS
function test(a, b, ...c) {
console.log(a);
console.log(b);
console.log(c);
}
test(1, 2, 3, 4); // a = 1, b = 2, c = [3, 4]
Functions: Rest parameters
C# params [] = JS …
function test(a, b, ...c) {
console.log(a);
console.log(b);
console.log(c);
}
test(...[1, 2, 3, 4]); // a = 1, b = 2, c = [3, 4]
test(...'pqrs'); // a = 'p', b = 'q', c = ['r ', 's']
Spread operator
JS Only (C# only for params)
let a = () => 'EcmaScript';
let b = (x) => x * x;
let c = x => x * x;
let d = x => { var y = x * x; return y; };
let e = (x, y) => x * y;
Arrow functions
C# lambda = JS arrow
Omit
braces
{ }
when multiple statements
• Default values
‣ var f = (x = 10) => x * x;

console.log(f()); // 100
• Rest parameters
‣ var x = (a, b, ...rest) => [a, b, rest];

console.log(x(1, 2, 3, 4)); // [ 1, 2, [3, 4] ]
• Return object literal
‣ var a = x => ({value: x}); // Must use ()

console.log(a(123)); // { value: 123 }
Arrow function options
JS Only
class Account extends Base {
constructor(name, initialAmount) {
super(name);
this.balance = initialAmount;
}
deposit(amount) {
this.balance += amount;
}
};
var acc = new Account('Bill', 0);
acc.deposit(100);
console.log(acc); // { name: 'Bill', balance: 100 }
Classes
JS still prototype inheritance & different syntax than C#
No
function keyword
Modules (direct)
// my-export.js
export function square(x) {
return x * x;
}
export let pi = 3.14;
// my-import.js
import { square, pi } from ‘./my-export’;
console.log(square(3)); // 9
console.log(pi); // 3.14
file-name = module name
Modules (default)
// my-export.js
function square(x) {
return x * x;
}
let pi = 3.14;
export default {square, pi};
// my-import.js
import my_export from './my-export';
console.log(my_export.square(3)); // 9
console.log(my_export.pi); // 3.14
C# namespaces look like JS modules
let data = [1, 22, 333, 4444, 55555];
let [a, , b, ...rest] = data;
console.log(a); // 1
console.log(b); // 333
console.log(rest); // [4444, 55555]
Destructuring: List matching
JS Only
let obj = {
name: 'EcmaScript',
year: 2015,
version: 6
};
let {name: a, year} = obj;
console.log(a); // 'EcmaScript'
console.log(year); // 2015
Destructuring: Object matching
JS Only
function test([value, {name}, year = 2017]) {
console.log(value); // 1
console.log(name); // EcmaScript
console.log(year); // 2017
}
test([1, {name: 'EcmaScript', year: 2015}]);
Destructuring: Parameters, nested & defaults
JS Only
function
parameter nested default
async function write() {
var txt = await read();
console.log(txt);
}
Async & Await (ES 2017)
C# = JS
• array
‣ [1, 2, ]
• object
‣ {

one: 1,

two: 2,

}
• function (ES 2017)
‣ function test(one, two, ) { }
‣ test(1, 2, );
Trailing commas
JS Only
let people = [
{ name: "Alice", age: 35 },
{ name: "Ben", age: 40 },
{ name: "Charlotte", age: 15 },
];
let where = people.filter(x => x.age >= 18); // adults only
let select = people.map(x => x.name); // names only
let all = people.every(x => x.age >= 18); // false
let any = people.some(x => x.age >= 18); // true
// Warning: In place, also updates people!
let orderedBy = people.sort((a, b) => a.age > b.age); // by age
“LINQ" functions on arrays
C# LINQ can be simulated by JS array methods
• http://kangax.github.io/compat-table/es6/
• http://kangax.github.io/compat-table/es2016plus/
Compatibility ES 2015, 2016…
• Babel
• Traceur
• TypeScript
Compiler: Transpile ES201X to ES5
• Install npm (by installing NodeJS)
• Command line:
‣ npm init
‣ npm install babel-cli babel-polyfill babel-preset-
es2015 babel-preset-es2016 babel-preset-2017 --save-dev
• Create file “.babelrc”:
{
"presets": ["es2015", "es2016", "es2017"]
}
• Command line (transpile all js-files in src-folder into the lib-folder):
‣ babel src --out-dir lib
Babel
• Why?
Packaging / Bundling + Minifying
• Bundling:
‣ Browsers can download max. 6 files at the same
time
• Minifying:
‣ Minimize download time
Packaging / Bundling + Minifying
Training: rick@oblicum.com or @rickbeerendonk
• ECMAScript
• 5, 2015, 2016, 2017…
• React
• Components, Properties, State, Events, Virtual DOM…
• Redux
• Actions, Reducers, Stores…
• Samples & Slides
• https://github.com/rickbeerendonk/ECMAScript-2015-2017-Demos


More Related Content

What's hot

Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...GeeksLab Odessa
 
Reactive, component 그리고 angular2
Reactive, component 그리고  angular2Reactive, component 그리고  angular2
Reactive, component 그리고 angular2Jeado Ko
 
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵Wanbok Choi
 
Why TypeScript?
Why TypeScript?Why TypeScript?
Why TypeScript?FITC
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
Proxies are Awesome!
Proxies are Awesome!Proxies are Awesome!
Proxies are Awesome!Brendan Eich
 
ADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersBartosz Kosarzycki
 
Advanced Object-Oriented JavaScript
Advanced Object-Oriented JavaScriptAdvanced Object-Oriented JavaScript
Advanced Object-Oriented JavaScriptecker
 
RxJS - 封裝程式的藝術
RxJS - 封裝程式的藝術RxJS - 封裝程式的藝術
RxJS - 封裝程式的藝術名辰 洪
 
ES2015 (ES6) Overview
ES2015 (ES6) OverviewES2015 (ES6) Overview
ES2015 (ES6) Overviewhesher
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual finalAhalyaR
 
LetSwift RxSwift 시작하기
LetSwift RxSwift 시작하기LetSwift RxSwift 시작하기
LetSwift RxSwift 시작하기Wanbok Choi
 
谈谈Javascript设计
谈谈Javascript设计谈谈Javascript设计
谈谈Javascript设计Alipay
 
미려한 UI/UX를 위한 여정
미려한 UI/UX를 위한 여정미려한 UI/UX를 위한 여정
미려한 UI/UX를 위한 여정SeungChul Kang
 
Продвинутая отладка JavaScript с помощью Chrome Dev Tools
Продвинутая отладка JavaScript с помощью Chrome Dev ToolsПродвинутая отладка JavaScript с помощью Chrome Dev Tools
Продвинутая отладка JavaScript с помощью Chrome Dev ToolsFDConf
 
Lambda Expressions in C++
Lambda Expressions in C++Lambda Expressions in C++
Lambda Expressions in C++Patrick Viafore
 
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRaimonds Simanovskis
 
Functional microscope - Lenses in C++
Functional microscope - Lenses in C++Functional microscope - Lenses in C++
Functional microscope - Lenses in C++Alexander Granin
 

What's hot (20)

Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
 
Reactive, component 그리고 angular2
Reactive, component 그리고  angular2Reactive, component 그리고  angular2
Reactive, component 그리고 angular2
 
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
 
Why TypeScript?
Why TypeScript?Why TypeScript?
Why TypeScript?
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Proxies are Awesome!
Proxies are Awesome!Proxies are Awesome!
Proxies are Awesome!
 
ADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developers
 
Advanced Object-Oriented JavaScript
Advanced Object-Oriented JavaScriptAdvanced Object-Oriented JavaScript
Advanced Object-Oriented JavaScript
 
RxJS - 封裝程式的藝術
RxJS - 封裝程式的藝術RxJS - 封裝程式的藝術
RxJS - 封裝程式的藝術
 
ES2015 (ES6) Overview
ES2015 (ES6) OverviewES2015 (ES6) Overview
ES2015 (ES6) Overview
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual final
 
LetSwift RxSwift 시작하기
LetSwift RxSwift 시작하기LetSwift RxSwift 시작하기
LetSwift RxSwift 시작하기
 
谈谈Javascript设计
谈谈Javascript设计谈谈Javascript设计
谈谈Javascript设计
 
미려한 UI/UX를 위한 여정
미려한 UI/UX를 위한 여정미려한 UI/UX를 위한 여정
미려한 UI/UX를 위한 여정
 
Продвинутая отладка JavaScript с помощью Chrome Dev Tools
Продвинутая отладка JavaScript с помощью Chrome Dev ToolsПродвинутая отладка JavaScript с помощью Chrome Dev Tools
Продвинутая отладка JavaScript с помощью Chrome Dev Tools
 
Lambda Expressions in C++
Lambda Expressions in C++Lambda Expressions in C++
Lambda Expressions in C++
 
JavaScript Core
JavaScript CoreJavaScript Core
JavaScript Core
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
 
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
 
Functional microscope - Lenses in C++
Functional microscope - Lenses in C++Functional microscope - Lenses in C++
Functional microscope - Lenses in C++
 

Viewers also liked

Communication And Regard
Communication And RegardCommunication And Regard
Communication And RegardJing Zhang
 
ES6 in Production [JSConfUY2015]
ES6 in Production [JSConfUY2015]ES6 in Production [JSConfUY2015]
ES6 in Production [JSConfUY2015]Guillermo Paz
 
Using JavaScript ES2015 (ES6), ES2016, ES2017 in production
Using JavaScript ES2015 (ES6), ES2016, ES2017 in productionUsing JavaScript ES2015 (ES6), ES2016, ES2017 in production
Using JavaScript ES2015 (ES6), ES2016, ES2017 in productionAnže Žnidaršič
 
Digital Bank, May 2014
Digital Bank, May 2014Digital Bank, May 2014
Digital Bank, May 2014Chris Skinner
 

Viewers also liked (7)

What's new in C# 6?
What's new in C# 6?What's new in C# 6?
What's new in C# 6?
 
Communication And Regard
Communication And RegardCommunication And Regard
Communication And Regard
 
ES6 in Production [JSConfUY2015]
ES6 in Production [JSConfUY2015]ES6 in Production [JSConfUY2015]
ES6 in Production [JSConfUY2015]
 
C# 6.0
C# 6.0C# 6.0
C# 6.0
 
Using JavaScript ES2015 (ES6), ES2016, ES2017 in production
Using JavaScript ES2015 (ES6), ES2016, ES2017 in productionUsing JavaScript ES2015 (ES6), ES2016, ES2017 in production
Using JavaScript ES2015 (ES6), ES2016, ES2017 in production
 
Programming in c#
Programming in c#Programming in c#
Programming in c#
 
Digital Bank, May 2014
Digital Bank, May 2014Digital Bank, May 2014
Digital Bank, May 2014
 

Similar to JavaScript 2016 for C# Developers

What's New in JavaScript
What's New in JavaScriptWhat's New in JavaScript
What's New in JavaScriptDan Cohn
 
React Native Evening
React Native EveningReact Native Evening
React Native EveningTroy Miles
 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptCaridy Patino
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchainedEduard Tomàs
 
Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to JavascriptAnjan Banda
 
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...Igalia
 
Javascript Basics
Javascript BasicsJavascript Basics
Javascript Basicsmsemenistyi
 
No JS and DartCon
No JS and DartConNo JS and DartCon
No JS and DartConanandvns
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Troy Miles
 
Apache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheelApache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheeltcurdt
 
NetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionNetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionPaulo Morgado
 
JavaScript - Agora nervoso
JavaScript - Agora nervosoJavaScript - Agora nervoso
JavaScript - Agora nervosoLuis Vendrame
 
JavaScript Futures—ES2017 and Beyond
JavaScript Futures—ES2017 and BeyondJavaScript Futures—ES2017 and Beyond
JavaScript Futures—ES2017 and BeyondJeff Strauss
 

Similar to JavaScript 2016 for C# Developers (20)

What's New in JavaScript
What's New in JavaScriptWhat's New in JavaScript
What's New in JavaScript
 
React Native Evening
React Native EveningReact Native Evening
React Native Evening
 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScript
 
Es6 hackathon
Es6 hackathonEs6 hackathon
Es6 hackathon
 
ES6: Features + Rails
ES6: Features + RailsES6: Features + Rails
ES6: Features + Rails
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchained
 
Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to Javascript
 
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
 
Javascript Basics
Javascript BasicsJavascript Basics
Javascript Basics
 
ES6 is Nigh
ES6 is NighES6 is Nigh
ES6 is Nigh
 
ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
 
Headless Js Testing
Headless Js TestingHeadless Js Testing
Headless Js Testing
 
No JS and DartCon
No JS and DartConNo JS and DartCon
No JS and DartCon
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1
 
Apache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheelApache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheel
 
NetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionNetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf Edition
 
JavaScript - Agora nervoso
JavaScript - Agora nervosoJavaScript - Agora nervoso
JavaScript - Agora nervoso
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript Futures—ES2017 and Beyond
JavaScript Futures—ES2017 and BeyondJavaScript Futures—ES2017 and Beyond
JavaScript Futures—ES2017 and Beyond
 
Javascript status 2016
Javascript status 2016Javascript status 2016
Javascript status 2016
 

More from Rick Beerendonk

Perform like an Olympian
Perform like an OlympianPerform like an Olympian
Perform like an OlympianRick Beerendonk
 
JavaScript innovaties: ECMAScript 6 & 7
JavaScript innovaties: ECMAScript 6 & 7JavaScript innovaties: ECMAScript 6 & 7
JavaScript innovaties: ECMAScript 6 & 7Rick Beerendonk
 
C# - Raise the bar with functional & immutable constructs (Dutch)
C# - Raise the bar with functional & immutable constructs (Dutch)C# - Raise the bar with functional & immutable constructs (Dutch)
C# - Raise the bar with functional & immutable constructs (Dutch)Rick Beerendonk
 
ReactJS.NET - Fast and Scalable Single Page Applications
ReactJS.NET - Fast and Scalable Single Page ApplicationsReactJS.NET - Fast and Scalable Single Page Applications
ReactJS.NET - Fast and Scalable Single Page ApplicationsRick Beerendonk
 
ReactJS maakt het web eenvoudig
ReactJS maakt het web eenvoudigReactJS maakt het web eenvoudig
ReactJS maakt het web eenvoudigRick Beerendonk
 
Niet onderhoudbare software in 10 makkelijke stappen
Niet onderhoudbare software in 10 makkelijke stappenNiet onderhoudbare software in 10 makkelijke stappen
Niet onderhoudbare software in 10 makkelijke stappenRick Beerendonk
 

More from Rick Beerendonk (6)

Perform like an Olympian
Perform like an OlympianPerform like an Olympian
Perform like an Olympian
 
JavaScript innovaties: ECMAScript 6 & 7
JavaScript innovaties: ECMAScript 6 & 7JavaScript innovaties: ECMAScript 6 & 7
JavaScript innovaties: ECMAScript 6 & 7
 
C# - Raise the bar with functional & immutable constructs (Dutch)
C# - Raise the bar with functional & immutable constructs (Dutch)C# - Raise the bar with functional & immutable constructs (Dutch)
C# - Raise the bar with functional & immutable constructs (Dutch)
 
ReactJS.NET - Fast and Scalable Single Page Applications
ReactJS.NET - Fast and Scalable Single Page ApplicationsReactJS.NET - Fast and Scalable Single Page Applications
ReactJS.NET - Fast and Scalable Single Page Applications
 
ReactJS maakt het web eenvoudig
ReactJS maakt het web eenvoudigReactJS maakt het web eenvoudig
ReactJS maakt het web eenvoudig
 
Niet onderhoudbare software in 10 makkelijke stappen
Niet onderhoudbare software in 10 makkelijke stappenNiet onderhoudbare software in 10 makkelijke stappen
Niet onderhoudbare software in 10 makkelijke stappen
 

Recently uploaded

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 

Recently uploaded (20)

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 

JavaScript 2016 for C# Developers

  • 1.
  • 2. #TechDaysNL @rickbeerendonk JavaScript for C# Developers Rick Beerendonk rick@oblicum.com
  • 3. Training: rick@oblicum.com or @rickbeerendonk • ECMAScript • 5, 2015, 2016, 2017… • React • Components, Properties, State, Events, Virtual DOM… • Redux • Actions, Reducers, Stores… • Samples & Slides • https://github.com/rickbeerendonk/ECMAScript-2015-2017-Demos

  • 5. 1. The following code is… var x = 10; 🙋 C# 🙎 JavaScript
  • 6. 1. The following code is… var x = 10; 🙋 C# 🎉 🙎 JavaScript 🎉
  • 7. 2. C#’s foreach in JavaScript is… 🙋 for .. in 🙎 for .. of
  • 8. 2. C#’s foreach in JavaScript is… 🙋 for .. in 🙎 for .. of 🎉
  • 9. 3. Indeterminate Number of Parameters in JavaScript C#: void Test(params int[] a) 🙋 function test([]a) 🙎 function test(…a)
  • 10. 3. Indeterminate Number of Parameters in JavaScript C#: void Test(params int[] a) 🙋 function test([]a) 🙎 function test(…a) 🎉
  • 11. 4. When does calling this function throw an error? function test(a, b) 1finger🙋 test(1) 2fingers🙋 test(1, 2) 3fingers🙋 test(1, 2, 3) 🙎 <never>
  • 12. 4. When does calling this function throw an error? function test(a, b) 1finger🙋 test(1) 2fingers🙋 test(1, 2) 3fingers🙋 test(1, 2, 3) 🙎 <never> 🎉
  • 13. 5. Call constructor of the parent class class Child extends Parent { constructor(name, value) { <???> this.balance = value; } } 🙋 base(name) 🙎 super(name)
  • 14. 5. Call constructor of the parent class class Child extends Parent { constructor(name, value) { <???> this.balance = value; } } 🙋 base(name) 🙎 super(name) 🎉
  • 15. • 2009: 5th Edition • 2015: 6th Edition • Changed to: ‣ Yearly releases (in June) ‣ Year = version number ECMAScript
  • 16. • Finished proposals • Active proposals Ecma International, Technical Committee 39 (TC39)
  • 17. • String • Number • Bool • Undefined • Null Primitive Data Types
  • 18. • String ‣ Single ('') or Double Quotes ("") ‣ C#: Char & String • Number ‣ C#: Double & Int • Bool • Undefined • Null Primitive Data Types
  • 19. Variable declarations var a = 1; if (true) { var a = 2; console.log(a); // 2 } console.log(a); // 2 let a = 1; if (true) { let a = 2; console.log(a); // 2 } console.log(a); // 1 C# var scoping = JS let scoping
  • 20. Constants var a = 1; if (true) { var a = 2; console.log(a); // 2 } console.log(a); // 2 // unchangeable const a = 1; if (true) { const a = 2; console.log(a); // 2 } console.log(a); // 1 Same as C#
  • 21. var name = "EcmaScript"; var version = 2015; Func<string> x = () => "hi!"; var result = $"This is about: {name} {version + 1} {x()}"; Console.WriteLine(result); // This is about: // EcmaScript 2016 hi! Template Strings C#
  • 22. var name = "EcmaScript"; var version = 2015; var x = () => "hi!"; var result = $"This is about: {name} {version + 1} {x()}"; console.log(result); // This is about: // EcmaScript 2016 hi! Template Strings
  • 23. var name = "EcmaScript"; var version = 2015; var x = () => "hi!"; var result = `This is about: ${name} ${version + 1} ${x()}`; console.log(result); // This is about: // EcmaScript 2016 hi! Template Strings JavaScript C# $"{}" = JS `${}`
  • 24. console.log('0'.padStart(3)); // ' 0' console.log('000'.padStart(1, '1')); // 000 console.log('000'.padStart(3, '1')); // 000 console.log('000'.padStart(5, '1')); // 11000 console.log('000'.padStart(5, '123')); // 12000 console.log('000'.padStart(7, '123')); // 1231000 String Padding (ES2017) C# String.PadLeft() = JS String.padStart()
  • 25. console.log('0'.padEnd(3)); // '0 ' console.log('000'.padEnd(1, '1')); // 000 console.log('000'.padEnd(3, '1')); // 000 console.log('000'.padEnd(5, '1')); // 00011 console.log('000'.padEnd(5, '123')); // 00012 console.log('000'.padEnd(7, '123')); // 0001231 String Padding (ES2017) C# String.PadRight() = JS String.padEnd()
  • 26. Equality: == vs === let i = 1; let s = '1'; console.log(i == s); // true (value) C# == is the same as JS === let i = 1; let s = '1'; console.log(i === s); // false (value + type)
  • 27. • If ‣ if (true || false) {
 console.log('positive');
 } else { 
 console.log('negative');
 } • Inline ‣ console.log(true || false ? 'positive' : 'negative'); Conditional Statements Same as C#
  • 28. • for ‣ for (let i = 0; i < 2; i++) { console.log(i)} • forEach ‣ [1, 2, 3].forEach((element, index, array) => console.log(`a[${index}] = ${element}`)) • for .. in ‣ Iterates over object properties • for .. of ‣ Iterates over iterable object (Array, String, Map, Set, etc.) Loops C# for = JS for C# foreach = JS for .. of
  • 29. let test = { [Symbol.iterator]: function*() { let current = 1; while (true) { yield current++; } } } Generators / Iterators C# function + yield + foreach = JS function* + yield + for .. of for (var n of test) { if (n > 10) { break; } console.log(n); }C# IEnumerable = JS Iterator
  • 30. function test(a, b) { console.log(a); console.log(b); } test(1); // a = 1, b = undefined test(1, 2, 3, 4); // a = 1, b = 2, 3 = ignored Functions: Overloads C# overload = JS one function
  • 31. function test(a = 11, b = '22') { console.log(a); console.log(b); } test(); // a = 11, b = '22' test(1, 2, 3, 4); // a = 1, b = 2, 3 & 4 = ignored Functions: Default parameters C# = JS
  • 32. function test(a, b, ...c) { console.log(a); console.log(b); console.log(c); } test(1, 2, 3, 4); // a = 1, b = 2, c = [3, 4] Functions: Rest parameters C# params [] = JS …
  • 33. function test(a, b, ...c) { console.log(a); console.log(b); console.log(c); } test(...[1, 2, 3, 4]); // a = 1, b = 2, c = [3, 4] test(...'pqrs'); // a = 'p', b = 'q', c = ['r ', 's'] Spread operator JS Only (C# only for params)
  • 34. let a = () => 'EcmaScript'; let b = (x) => x * x; let c = x => x * x; let d = x => { var y = x * x; return y; }; let e = (x, y) => x * y; Arrow functions C# lambda = JS arrow Omit braces { } when multiple statements
  • 35. • Default values ‣ var f = (x = 10) => x * x;
 console.log(f()); // 100 • Rest parameters ‣ var x = (a, b, ...rest) => [a, b, rest];
 console.log(x(1, 2, 3, 4)); // [ 1, 2, [3, 4] ] • Return object literal ‣ var a = x => ({value: x}); // Must use ()
 console.log(a(123)); // { value: 123 } Arrow function options JS Only
  • 36. class Account extends Base { constructor(name, initialAmount) { super(name); this.balance = initialAmount; } deposit(amount) { this.balance += amount; } }; var acc = new Account('Bill', 0); acc.deposit(100); console.log(acc); // { name: 'Bill', balance: 100 } Classes JS still prototype inheritance & different syntax than C# No function keyword
  • 37. Modules (direct) // my-export.js export function square(x) { return x * x; } export let pi = 3.14; // my-import.js import { square, pi } from ‘./my-export’; console.log(square(3)); // 9 console.log(pi); // 3.14 file-name = module name
  • 38. Modules (default) // my-export.js function square(x) { return x * x; } let pi = 3.14; export default {square, pi}; // my-import.js import my_export from './my-export'; console.log(my_export.square(3)); // 9 console.log(my_export.pi); // 3.14 C# namespaces look like JS modules
  • 39. let data = [1, 22, 333, 4444, 55555]; let [a, , b, ...rest] = data; console.log(a); // 1 console.log(b); // 333 console.log(rest); // [4444, 55555] Destructuring: List matching JS Only
  • 40. let obj = { name: 'EcmaScript', year: 2015, version: 6 }; let {name: a, year} = obj; console.log(a); // 'EcmaScript' console.log(year); // 2015 Destructuring: Object matching JS Only
  • 41. function test([value, {name}, year = 2017]) { console.log(value); // 1 console.log(name); // EcmaScript console.log(year); // 2017 } test([1, {name: 'EcmaScript', year: 2015}]); Destructuring: Parameters, nested & defaults JS Only function parameter nested default
  • 42. async function write() { var txt = await read(); console.log(txt); } Async & Await (ES 2017) C# = JS
  • 43. • array ‣ [1, 2, ] • object ‣ {
 one: 1,
 two: 2,
 } • function (ES 2017) ‣ function test(one, two, ) { } ‣ test(1, 2, ); Trailing commas JS Only
  • 44. let people = [ { name: "Alice", age: 35 }, { name: "Ben", age: 40 }, { name: "Charlotte", age: 15 }, ]; let where = people.filter(x => x.age >= 18); // adults only let select = people.map(x => x.name); // names only let all = people.every(x => x.age >= 18); // false let any = people.some(x => x.age >= 18); // true // Warning: In place, also updates people! let orderedBy = people.sort((a, b) => a.age > b.age); // by age “LINQ" functions on arrays C# LINQ can be simulated by JS array methods
  • 46. • Babel • Traceur • TypeScript Compiler: Transpile ES201X to ES5
  • 47. • Install npm (by installing NodeJS) • Command line: ‣ npm init ‣ npm install babel-cli babel-polyfill babel-preset- es2015 babel-preset-es2016 babel-preset-2017 --save-dev • Create file “.babelrc”: { "presets": ["es2015", "es2016", "es2017"] } • Command line (transpile all js-files in src-folder into the lib-folder): ‣ babel src --out-dir lib Babel
  • 48. • Why? Packaging / Bundling + Minifying
  • 49. • Bundling: ‣ Browsers can download max. 6 files at the same time • Minifying: ‣ Minimize download time Packaging / Bundling + Minifying
  • 50. Training: rick@oblicum.com or @rickbeerendonk • ECMAScript • 5, 2015, 2016, 2017… • React • Components, Properties, State, Events, Virtual DOM… • Redux • Actions, Reducers, Stores… • Samples & Slides • https://github.com/rickbeerendonk/ECMAScript-2015-2017-Demos