Skip to content

Commit

Permalink
new video
Browse files Browse the repository at this point in the history
  • Loading branch information
realtux committed Feb 20, 2022
1 parent b63ac8c commit 51ca29b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
33 changes: 33 additions & 0 deletions 154/async.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// node.js style callbacks
function1(args, (err, data) => {
function2(args, (err, data) => {
function3(args, (err, data) => {

});
});
});

// promise style callbacks
function1(args)
.then(data => {
return function2(args);
})
.then(data => {
return function3(args);
})
.catch(err => {
console.log(err);
});

// async/await style
try {
let data1 = await function1(args);
let data2 = await function2(args);
let data3 = await function3(args);

function4().then(data => {
console.log('done');
});
} catch (e) {
console.log(e);
}
8 changes: 8 additions & 0 deletions 154/notes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
tips:
- stay up-to-date on the latest version of node.js
- make use of well supported npm modules
- use a bundler for frontend things
- use async/await, normal promises to defer
- use strict equality === exclusively
- don't block the event loop
- avoid clever one-liners
14 changes: 14 additions & 0 deletions 154/oneline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// normal
switch (a) {
case 1:
console.log('one');
break;
case 2:
console.log('two');
break;
default:
console.log('none');
}

// one liner
console.log(a === 1 ? 'one' : a === 2 ? 'two' : 'none');

0 comments on commit 51ca29b

Please sign in to comment.