Skip to content

Comments

「変数のスコープ」の項をリライト#927

Open
nakaterm wants to merge 3 commits intomainfrom
rewrite-variable-scope
Open

「変数のスコープ」の項をリライト#927
nakaterm wants to merge 3 commits intomainfrom
rewrite-variable-scope

Conversation

@nakaterm
Copy link
Contributor

@nakaterm nakaterm commented Feb 15, 2026

resolves #815

@nakaterm nakaterm force-pushed the rewrite-variable-scope branch from bf5fed0 to 1153079 Compare February 15, 2026 10:01
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 15, 2026

Deploying utcode-learn with  Cloudflare Pages  Cloudflare Pages

Latest commit: a5ef48a
Status: ✅  Deploy successful!
Preview URL: https://e1538c45.utcode-learn.pages.dev
Branch Preview URL: https://rewrite-variable-scope.utcode-learn.pages.dev

View logs

@nakaterm nakaterm force-pushed the rewrite-variable-scope branch from 1153079 to 1c4b02e Compare February 15, 2026 10:02

function greet() {
guestCount += 1;
guestCount = guestCount + 1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここで初出の += が出てくるとノイズなので、ここでは普通に今まで扱った方法で書き、下のコラム内で「これを += に書き換えられる」という説明をするようにしています


greet();

// document.write(message); これはエラーになる
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

エラーになるサンプルコードを提供しない、という方針に従いコメントアウトしている

@nakaterm nakaterm requested review from chvmvd and Copilot and removed request for chvmvd February 15, 2026 11:22
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

「変数のスコープ」セクションを、具体例(関数内のローカル変数/外側で宣言した変数の参照)を用いて説明し直し、合わせて複合代入演算子の説明導線を整理するPRです。

Changes:

  • スコープの説明を、message のローカルスコープ例(関数内のみ参照可)で具体化
  • 外側(関数外)で宣言した変数を関数内から参照・更新できる例を維持しつつ、説明文をリライト
  • 複合代入演算子の説明を「guestCount = guestCount + 1guestCount += 1」の流れに整理

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


```javascript
function greet() {
let message = "Hello!";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここでconstではなく、letを使った理由が分からなかったのですが、何かあったりしますか?


```javascript
function greet() {
let message = "Hello!";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(optional)

上の説明では、メッセージが"Hello!"ではなく、"Hello World!"になっているため、そちらに統一すると認知負荷が少し小さくなるかもしれません。

```javascript
// 関数を定義しておけば
function greet() {
document.write("Hello World!");
}
// 後から呼び出すことができる
greet();
greet();
```


```javascript
function greet() {
let message = "Hello!";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同様にletconst


greet();

// document.write(message); これはエラーになる
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(optional)

これを単にコメントアウトすると、document.write(message); これはエラーになるとなってしまい、これも構文エラーになってしまうため、単にコメントアウトしても構文エラーにならないようになっていると少し親切かもしれません。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

スコープの話の例を追加する

2 participants