Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

> const lol = a + b + c – f * ( n + o ); NaN

Slide 13

Slide 13 text

> NaN >= 0 false

Slide 14

Slide 14 text

> NaN <= 0 false

Slide 15

Slide 15 text

> typeof NaN number

Slide 16

Slide 16 text

( a + b ) + c = a + ( b + c ) // mathematically true > 0.1 + 0.2 === 0.3 false > ( a + b ) + c == a + ( b + c ) ??

Slide 17

Slide 17 text

> 0.1 + 0.2 0.30000000000000004

Slide 18

Slide 18 text

> Math.round(0.4999999999999999722444243843710864894092082) 0 > Math.round(0.4999999999999999722444243843710864894092083) 1 I’ve got 99 problems but JavaScript ain’t 1.0000000000000009

Slide 19

Slide 19 text

> [ 2, 10 ].sort() [ 10, 2 ]

Slide 20

Slide 20 text

> ['10','10','10', '10', '10'].map( parseInt ) [ 10, NaN, 2, 3, 4 ]

Slide 21

Slide 21 text

> typeof undefined // undefined > typeof true // boolean > typeof "hello" // string > typeof 1 // number > typeof {lol:true} // object > typeof [1,2,3] // object > typeof null // object

Slide 22

Slide 22 text

> null == 0 // false > null > 0 // false > null < 0 // false > null >= 0 // true > null <= 0 // true > Number( null ) // 0

Slide 23

Slide 23 text

> false > null > undefined > "" > 0 > NaN

Slide 24

Slide 24 text

> wat.test("javascript"); // true > wat.test("wat r u doin"); // false > const wat = /a/g;

Slide 25

Slide 25 text

// undefined function troll() { return { haha: "ha!" }; } troll(); // automatic semi-colon

Slide 26

Slide 26 text

const arr = []; arr[1] = 1; arr[3] = 2; arr[10] = 3; arr.length // 11 arr[-1] = 4; arr.s = 5; arr.length // 11

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

No content

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

No content

Slide 87

Slide 87 text

No content

Slide 88

Slide 88 text

No content

Slide 89

Slide 89 text

No content

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

No content

Slide 92

Slide 92 text

No content

Slide 93

Slide 93 text

No content

Slide 94

Slide 94 text

• trimStart() and trimEnd() • Optional Catch • Object.fromEntries() • flat() and flatMap()

Slide 95

Slide 95 text

// String.prototype.trimStart() and trimEnd() const what = " \n \t what is love".trimStart(); const bacon = "bacon don't hurt me\n \n \n \t ".trimEnd(); const obj = { lyric: what + " " + bacon }; console.log( obj ); // { lyric: "what is love bacon don't hurt me" }

Slide 96

Slide 96 text

// Optional Catch try { console.log( "Error objects?" ); throw new Error( "LOL" ); } catch { console.log( "We don't need no stinkin' Error objects!" ); } // Error objects? // We don't need no stinkin' Error objects!

Slide 97

Slide 97 text

// Object.fromEntries() const props = [ [ "what", "is love" ], [ "bacon", "don't hurt me" ], [ "love", true ] ]; const obj = Object.fromEntries( props ); console.log( obj ); // { what: 'is love', bacon: "don't hurt me", love: true }

Slide 98

Slide 98 text

// Array.prototype.flat() and .flatMap() const nestedArrays = [ "bacon", "eggs", [ "waffles" ], [ "coffee" ], [ "doughnuts", "milk" ] ]; const flattened = nestedArrays.flat(); console.log( flattened ); // [ 'bacon', 'eggs', 'waffles', 'coffee', 'doughnuts', 'milk' ]

Slide 99

Slide 99 text

• Nullish coalescing ?? operator • Optional ?. chaining • Promise.allSettled() • Dynamic import()

Slide 100

Slide 100 text

// Logical OR || operator works with any falsy value console.log( 0 || "zero value" ); // zero value console.log( "" || "empty string value" ); // empty string value console.log( false || "false value" ); // false value console.log( null || "null value" ); // null value console.log( undefined || "undefined value" ); // undefined value

Slide 101

Slide 101 text

// Nullish (??) operator only works with null/undefined console.log( 0 ?? "zero value" ); // 0 console.log( "" ?? "empty string value" ); // "" console.log( false ?? "false value" ); // false console.log( null ?? "null value" ); // null value console.log( undefined ?? "undefined value" ); // undefined value

Slide 102

Slide 102 text

// The old way of checking for potentially missing properties const customer = {}; let city; try { city = customer.address.city; } catch ( err ) { console.log( err ); // TypeError: Cannot read properties of undefined (reading 'city’) } console.log( city ); // undefined

Slide 103

Slide 103 text

// The old way of checking for potentially missing properties const customer = {}; let city; if ( customer && customer.address && customer.address.city ) { city = customer.address.city; } console.log( city ); // undefined

Slide 104

Slide 104 text

// Optional ?. Chaining const customer1 = {}; const customer2 = { address: { city: "Nashville" } }; const city1 = customer1?.address?.city; // undefined const city2 = customer2?.address?.city; // Nashville

Slide 105

Slide 105 text

// Promise.allSettled() const p1 = new Promise( ( resolve, reject ) => { setTimeout( () => { resolve( "p1 resolved" ); }, 250 ); } ); const p2 = new Promise( ( resolve, reject ) => { setTimeout( () => { resolve( "p2 resolved" ); }, 450 ); } ); const p3 = new Promise( ( resolve, reject ) => { setTimeout( () => { reject( "p3 rejected" ); }, 650 ); } );

Slide 106

Slide 106 text

// Promise.allSettled() const results = await Promise.allSettled( [ p1, p2, p3 ] ); console.log( results ); // [ // { status: 'fulfilled', value: 'p1 resolved' }, // { status: 'fulfilled', value: 'p2 resolved' }, // { status: 'rejected', reason: 'p3 rejected' } // ]

Slide 107

Slide 107 text

// Dynamic import() const example = await import( "./importExample.js" ); console.log( example ); // [Module: null prototype] { // default: { whatIsLove: [Function: whatIsLove] } // }

Slide 108

Slide 108 text

• String.prototype.replaceAll() • Promise.any() • Logical assignment operators ||= &&= ??= • Numeric separator

Slide 109

Slide 109 text

// Old string replace() const qs = "q=what+is+love"; const nope = qs.replace( "+", " " ); // "q=what is+love”

Slide 110

Slide 110 text

// Old string replace() const qs = "q=what+is+love"; const nope = qs.replace( "+", " " ); // "q=what is+love” const yep = qs.replace( /\+/g, " " ); // "q=what is love"

Slide 111

Slide 111 text

// Old string replace() const qs = "q=what+is+love"; const nope = qs.replace( "+", " " ); // "q=what is+love” const yep = qs.replace( /\+/g, " " ); // "q=what is love" const lol = qs.split( "+" ).join( " " ); // "q=what is love"

Slide 112

Slide 112 text

// String.prototype.replaceAll() const n00b = "Hey, I can leet speak, too, yo"; const l33t = n00b.replaceAll( "e", "3" ) .replaceAll( "o", "0" ) .replaceAll( ",", "" ) .toLowerCase(); console.log( l33t );

Slide 113

Slide 113 text

// String.prototype.replaceAll() const n00b = "Hey, I can leet speak, too, yo"; const l33t = n00b.replaceAll( "e", "3" ) .replaceAll( "o", "0" ) .replaceAll( ",", "" ) .toLowerCase(); console.log( l33t ); // h3y i can l33t sp3ak t00 y0

Slide 114

Slide 114 text

// Promise.any() example const p1 = new Promise( res => { setTimeout( () => { res( "knock, knock" ); }, 200 ); } ); const p2 = new Promise( res => { setTimeout( () => { res( "who's there?" ); }, 400 ); } ); const interruptingCow = Promise.reject( "MOO!!" ); const lol = await Promise.any( [ p1, p2, interruptingCow ] ); console.log( lol );

Slide 115

Slide 115 text

// Promise.any() example const p1 = new Promise( res => { setTimeout( () => { res( "knock, knock" ); }, 200 ); } ); const p2 = new Promise( res => { setTimeout( () => { res( "who's there?" ); }, 400 ); } ); const interruptingCow = Promise.reject( "MOO!!" ); const lol = await Promise.any( [ p1, p2, interruptingCow ] ); console.log( lol ); // knock, knock

Slide 116

Slide 116 text

// Logical assignment operators // OR only assigns if x is a falsy value let x = false; x ||= "yes"; x ||= "what is";

Slide 117

Slide 117 text

// Logical assignment operators // OR only assigns if x is a falsy value let x = false; x ||= "yes"; x ||= "what is"; // yes

Slide 118

Slide 118 text

// Logical assignment operators // OR only assigns if x is a falsy value let x = false; x ||= "yes"; x ||= "what is"; // yes // AND assigns if y is not a falsy value let y = "gimme-all-yer"; y &&= "i love";

Slide 119

Slide 119 text

// Logical assignment operators // OR only assigns if x is a falsy value let x = false; x ||= "yes"; x ||= "what is"; // yes // AND assigns if y is not a falsy value let y = "gimme-all-yer"; y &&= "i love"; // i love

Slide 120

Slide 120 text

// Logical assignment operators // OR only assigns if x is a falsy value let x = false; x ||= "yes"; x ||= "what is"; // yes // AND assigns if y is not a falsy value let y = "gimme-all-yer"; y &&= "i love"; // i love // ??= Nullish only assigns if z is null or undefined let z = "bacon"; z ??= y;

Slide 121

Slide 121 text

// Logical assignment operators // OR only assigns if x is a falsy value let x = false; x ||= "yes"; x ||= "what is"; // yes // AND assigns if y is not a falsy value let y = "gimme-all-yer"; y &&= "i love"; // i love // ??= Nullish only assigns if z is null or undefined let z = "bacon"; z ??= y; // bacon

Slide 122

Slide 122 text

// Numeric separators example const numbersMakeMeSad = 10204005020405;

Slide 123

Slide 123 text

// Numeric separators example const numbersMakeMeSad = 10204005020405; const notSoBad = 10_204_005_020_405;

Slide 124

Slide 124 text

// Numeric separators example const numbersMakeMeSad = 10204005020405; const notSoBad = 10_204_005_020_405; console.log( numbersMakeMeSad === notSoBad ); // true

Slide 125

Slide 125 text

• Array.prototype.at() & String .at() • Top-level await • Error cause • New static, private class members

Slide 126

Slide 126 text

// String and Array at() const arr = [ "what", "is", "love", "bacon", "don't", "hurt", "me" ]; console.log( arr.at( 3 ) );

Slide 127

Slide 127 text

// String and Array at() const arr = [ "what", "is", "love", "bacon", "don't", "hurt", "me" ]; console.log( arr.at( 3 ) ); // bacon

Slide 128

Slide 128 text

// String and Array at() const arr = [ "what", "is", "love", "bacon", "don't", "hurt", "me" ]; console.log( arr.at( 3 ) ); // bacon console.log( arr.at( -1 ) );

Slide 129

Slide 129 text

// String and Array at() const arr = [ "what", "is", "love", "bacon", "don't", "hurt", "me" ]; console.log( arr.at( 3 ) ); // bacon console.log( arr.at( -1 ) ); // me

Slide 130

Slide 130 text

// String and Array at() const arr = [ "what", "is", "love", "bacon", "don't", "hurt", "me" ]; console.log( arr.at( 3 ) ); // bacon console.log( arr.at( -1 ) ); // me const msg = "I love rock n' roll"; console.log( msg.at( 4 ) );

Slide 131

Slide 131 text

// String and Array at() const arr = [ "what", "is", "love", "bacon", "don't", "hurt", "me" ]; console.log( arr.at( 3 ) ); // bacon console.log( arr.at( -1 ) ); // me const msg = "I love rock n' roll"; console.log( msg.at( 4 ) ); // v

Slide 132

Slide 132 text

// Top-level await async function sleep( ms ) { const msg = `I slept for ${ ms } milliseconds`; return new Promise( resolve => setTimeout( () => resolve( msg ), ms ) ); } const result = await sleep( 500 ); console.log( result ); console.log( "finished" );

Slide 133

Slide 133 text

// Top-level await async function sleep( ms ) { const msg = `I slept for ${ ms } milliseconds`; return new Promise( resolve => setTimeout( () => resolve( msg ), ms ) ); } const result = await sleep( 500 ); console.log( result ); console.log( "finished" ); // I slept for 500 milliseconds // finished

Slide 134

Slide 134 text

// Error _with_ a cause function breakin() { throw new Error( "Gonna stop you cold" ); } function breakin2ElectricBoogaloo() { try { breakin(); } catch ( err ) { throw new Error( "Whacked", { cause: err } ); } }

Slide 135

Slide 135 text

// Error _with_ a cause function shutUpAndDance() { try { breakin2ElectricBoogaloo(); } catch ( err ) { console.log( err ); } } shutUpAndDance();

Slide 136

Slide 136 text

// Error _with_ a cause shutUpAndDance(); // Error: Whacked // at breakin2ElectricBoogaloo ... // [cause]: Error: Gonna stop you cold // at breakin ... // }

Slide 137

Slide 137 text

// Private and static class members class Of86GlenbrookNorthHigh { #reason; static car = "Ferrari"; static #miles = 26000; constructor( reason ) { this.#reason = reason; } ... }

Slide 138

Slide 138 text

// Private and static class members class Of86GlenbrookNorthHigh { #reason; static car = "Ferrari"; static #miles = 26000; static #getMiles() { Of86GlenbrookNorthHigh.#miles += 123; return Of86GlenbrookNorthHigh.#miles; } }

Slide 139

Slide 139 text

// Private and static class members class Of86GlenbrookNorthHigh { #reason; static car = "Ferrari"; static #miles = 26000; static #getMiles() { … } #carStatus() { const miles = Of86GlenbrookNorthHigh.#getMiles(); return `The ${ Of86GlenbrookNorthHigh.car } has ${ miles } miles`; } }

Slide 140

Slide 140 text

// Private and static class members class Of86GlenbrookNorthHigh { #carStatus() { … } status() { console.log( `Ferris can't go to school, he's ${ this.#reason }` ); console.log( this.#carStatus() ); } }

Slide 141

Slide 141 text

// Private and static class members const myClass = new Of86GlenbrookNorthHigh( "sick" ); myClass.status(); // Ferris can't go to school, he's sick // The Ferrari has 26123 miles

Slide 142

Slide 142 text

// Private and static class members const myClass = new Of86GlenbrookNorthHigh( "sick" ); myClass.status(); myClass.#carStatus(); // SyntaxError console.log( myClass.#car ); // SyntaxError

Slide 143

Slide 143 text

No content

Slide 144

Slide 144 text

No content

Slide 145

Slide 145 text

No content

Slide 146

Slide 146 text

No content

Slide 147

Slide 147 text

No content

Slide 148

Slide 148 text

No content

Slide 149

Slide 149 text

No content

Slide 150

Slide 150 text

No content

Slide 151

Slide 151 text

No content

Slide 152

Slide 152 text

No content

Slide 153

Slide 153 text

No content

Slide 154

Slide 154 text

No content

Slide 155

Slide 155 text

No content

Slide 156

Slide 156 text

No content

Slide 157

Slide 157 text

No content

Slide 158

Slide 158 text

No content

Slide 159

Slide 159 text

No content

Slide 160

Slide 160 text

No content

Slide 161

Slide 161 text

No content

Slide 162

Slide 162 text

No content

Slide 163

Slide 163 text

No content

Slide 164

Slide 164 text

No content