incrementAgeの課題に佐藤を追加#537
Conversation
Deploying with
|
| Latest commit: |
7c9fb94
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://382e769e.utcode-learn.pages.dev |
| Branch Preview URL: | https://sato-increment-age.utcode-learn.pages.dev |
|
|
||
| const tanaka = { name: "田中", age: 18 }; | ||
| const tanaka = { name: "田中", age: 18 }, | ||
| sato = { name: "佐藤", age: 22 }; |
There was a problem hiding this comment.
,区切りで複数の宣言ができることを教材で教えていないので、それぞれ分けて宣言していただけるとありがたいです。
There was a problem hiding this comment.
というか多分これだと sato がグローバルスコープになるので好ましくないです
There was a problem hiding this comment.
これはもともとtanakaもグローバルスコープじゃないんですか?
There was a problem hiding this comment.
この場合はそうなんですけど、const a = 1, b = 2 のようにすると const a = 1 と b = 2 という2つの文(式)として解釈されるので、他の関数などの中に入れたとしても b (sato) はグローバルスコープになってしまいます。
cf.
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Comma_operator
There was a problem hiding this comment.
訂正: 今試したところ、カンマ区切りはいい感じに解釈してくれるみたいです。
const a = b = 1; と間違えてました
There was a problem hiding this comment.
constもletもvarもカンマ区切りで複数の変数を宣言できるはずです
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Statements/const
それはそれとしてあとで2文にわけておきます
|
|
||
| const tanaka = { name: "田中", age: 18 }; | ||
| const tanaka = { name: "田中", age: 18 }, | ||
| sato = { name: "佐藤", age: 22 }; |
There was a problem hiding this comment.
というか多分これだと sato がグローバルスコープになるので好ましくないです
| sato = { name: "佐藤", age: 22 }; | ||
| const nextYearTanaka = incrementAge(tanaka); | ||
| document.write(nextYearTanaka.age); // 19 と表示されてほしい | ||
| const nextYearSato = incrementAge(sato); // 同じ関数を tanaka と sato に使い回せる |
There was a problem hiding this comment.
この説明は関数のところでしてるので必要ないのでは?
|
レビューで指摘された箇所はたぶん直しました。 |
fix #261