回答編集履歴

4

コメント追加

2022/10/03 15:50

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -6,14 +6,14 @@
6
6
  async function getTodo() { // async関数は必ずPromiseを返す
7
7
  try {
8
8
  const res = await axios.get("https://jsonplaceholder.typicode.com/todos/1");
9
- return res.data.title; // .then代わりにawaitで戻り値を受け取れる
9
+ return res.data.title; // Promise.then代わってawaitで戻り値を受け取れる
10
10
  } catch (err) {
11
11
  return "error";
12
12
  }
13
13
  }
14
14
 
15
15
  async function main() {
16
- const todo = await getTodo(); // getTodo()はPromise、awaitでPromiseから戻り値を取り出す
16
+ const todo = await getTodo(); // getTodo()はPromise、awaitでPromiseから戻り値を受け
17
17
  console.log(todo);
18
18
  }
19
19
 

3

コメント追記

2022/10/03 15:47

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -6,7 +6,7 @@
6
6
  async function getTodo() { // async関数は必ずPromiseを返す
7
7
  try {
8
8
  const res = await axios.get("https://jsonplaceholder.typicode.com/todos/1");
9
- return res.data.title;
9
+ return res.data.title; // .thenの代わりにawaitで戻り値を受け取れる
10
10
  } catch (err) {
11
11
  return "error";
12
12
  }

2

コメント追記

2022/10/03 13:25

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -3,7 +3,7 @@
3
3
  ```js
4
4
  import axios from "axios";
5
5
 
6
- async function getTodo() {
6
+ async function getTodo() { // async関数は必ずPromiseを返す
7
7
  try {
8
8
  const res = await axios.get("https://jsonplaceholder.typicode.com/todos/1");
9
9
  return res.data.title;

1

コメント追記

2022/10/03 13:21

投稿

shiracamus
shiracamus

スコア5406

test CHANGED
@@ -13,7 +13,7 @@
13
13
  }
14
14
 
15
15
  async function main() {
16
- const todo = await getTodo();
16
+ const todo = await getTodo(); // getTodo()はPromise、awaitでPromiseから戻り値を取り出す
17
17
  console.log(todo);
18
18
  }
19
19