SlideShare una empresa de Scribd logo
1 de 50
Descargar para leer sin conexión
#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


Más contenido relacionado

La actualidad más candente

ADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developers
Bartosz Kosarzycki
 

La actualidad más candente (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++
 

Destacado

Destacado (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 a JavaScript 2016 for C# Developers

Similar a 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
 

Más de Rick Beerendonk

Más de 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
 

Último

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
anilsa9823
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
anilsa9823
 

Último (20)

Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
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 ...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
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 ...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
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
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 

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