Live data from Hacker News

A Modern JavaScript Tutorial

javascript.info

11–20 of 299 posts

Re: A Modern JavaScript Tutorial

#11

The ninja code section is pure sarcasm, right? I'm not sure now which sections are and aren't.

The section is clearly dripping with irony. They even have an "Irony detected" box at the very top which acts as the sarcasm/satire tag so many people seem to use to bang over our heads that it's not serious.

Re: A Modern JavaScript Tutorial

#12
post #5

The default way promises are used is now async/await. `.then()` should not be introduced as anything more than 'you may find this in older codebases'.

Can you point to anything other than saying "this is obvious"?

No, just experience with a lot of codebases.

Here's a simple question to ask yourself: what if non-IO operations allowed you to use the .then() syntax? If you have the choice to use:

   1 + 1.then(function(result) { ... }
vs

   const result = 1 + 1
Which would you choose?

Re: A Modern JavaScript Tutorial

#13
post #5

The default way promises are used is now async/await. `.then()` should not be introduced as anything more than 'you may find this in older codebases'.

Maybe some codebases mandate it, but it's very common to use either style when it makes the most sense. The classic syntax is by no means deprecated or superseded by async/await.

Re: A Modern JavaScript Tutorial

#14
post #12

Earlier quoted context omitted.

Can you point to anything other than saying "this is obvious"?

No, just experience with a lot of codebases. Here's a simple question to ask yourself: what if non-IO operations allowed you to use the .then() syntax? If you have the choice to use: 1 + 1.then(function(result) { ... } vs const result = 1 + 1 Which would you choose?

Using then() doesn't pause execution of the callsite function, while await does. Surely that's a relevant difference here?

It doesn't seem unreasonable to use then() to express: "Run this anonymous function whenever the async thing completes. Meanwhile let's do this other stuff right now."

Re: A Modern JavaScript Tutorial

#15
post #5

The default way promises are used is now async/await. `.then()` should not be introduced as anything more than 'you may find this in older codebases'.

async/await is excellent syntax when you want things to happen one after another. That's the usual case, and that's what I find myself using 95% of the time.

However, when you want a more fine-grained concurrent execution of different asynchronous things, then() still could be very useful.

Re: A Modern JavaScript Tutorial

#17
post #5

The default way promises are used is now async/await. `.then()` should not be introduced as anything more than 'you may find this in older codebases'.

That’s probably good general advice.

One problem. I’m increasingly coming across devs who’ve never used Promises directly, only async/await. They’re introducing all kinds of problems into code because they don’t have that foundational understanding of Promises. I think it’s essential to know how Promises work, even if we generally recommend async/await.

Also, Promise interface can do things that async/await cannot, such as Promise.all, and other unusual async execution scenarios. It’s important to have those tools in your belt.

Re: A Modern JavaScript Tutorial

#19
post #5

The default way promises are used is now async/await. `.then()` should not be introduced as anything more than 'you may find this in older codebases'.

> The default way promises are used is now async/await. `.then()` should not be introduced as anything more than 'you may find this in older codebases'.

No, because you might have to write explicit promises in the browser with async API that are callback based.

You need to understand how promises work to use async/await at first place anyway.

Just like it's better to understand how prototypal inheritance works in JS BEFORE even using a single class declaration.

Re: A Modern JavaScript Tutorial

#20
> According to your browser language headers, you know Chinese. Please help to translate the tutorial into your language! Thank you!

I'm curious. How are my language preferences exposed through HTTP headers?

I think this was a charming way to request volunteers for translation, but I was a bit taken aback.

Post reply on HN