Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typeof 演算子で function が返ることについて補足する #1455

Closed
kangetsu121 opened this issue Aug 6, 2022 · 1 comment · Fixed by #1466
Closed

typeof 演算子で function が返ることについて補足する #1455

kangetsu121 opened this issue Aug 6, 2022 · 1 comment · Fixed by #1466
Labels
Status: Proposal 提案段階の状態

Comments

@kangetsu121
Copy link
Contributor

該当ページ

リクエスト/提案内容

文中で、JavaScript のデータ型について以下のように説明しており、ここを読んだ段階では、読者は関数 (function) を typeof 演算子で評価した結果として object が返ることを期待すると思います。

データ型を細かく見ていくと、7つのプリミティブ型とオブジェクトからなります。
- プリミティブ型(基本型)
- 真偽値(Boolean): `true`または`false`のデータ型
- 数値(Number): `42``3.14159` などの数値のデータ型
- 巨大な整数(BigInt): ES2020から追加された`9007199254740992n`などの任意精度の整数のデータ型
- 文字列(String): `"JavaScript"` などの文字列のデータ型
- undefined: 値が未定義であることを意味するデータ型
- null: 値が存在しないことを意味するデータ型
- シンボル(Symbol): ES2015から追加された一意で不変な値のデータ型
- オブジェクト(複合型)
- プリミティブ型以外のデータ
- オブジェクト、配列、関数、正規表現、Dateなど

しかし、そのすぐ下の typeof 演算子を使った確認では、評価結果として function が返る例が示されています。

```js
console.log(typeof true);// => "boolean"
console.log(typeof 42); // => "number"
console.log(typeof 9007199254740992n); // => "bigint"
console.log(typeof "JavaScript"); // => "string"
console.log(typeof Symbol("シンボル"));// => "symbol"
console.log(typeof undefined); // => "undefined"
console.log(typeof null); // => "object"
console.log(typeof ["配列"]); // => "object"
console.log(typeof { "key": "value" }); // => "object"
console.log(typeof function() {}); // => "function"
```

console.log(typeof function() {}); // => "function"

ただしその後も typeof 演算子の評価結果としての function についての言及はないため、どこかでこの結果について補足するのはいかがでしょうか。
詳細に入りすぎても混乱すると思うので、コラム的に言及するのみで良いとは思います。

MDN の解説を参照するだけでも良いかと思いましたが、初学者はかえって混乱すると思ったので、できれば文中で補足があるとありがたいと思いました。

ご検討よろしくお願いします。

期待する結果

以下のいずれかが反映される:

a. typeof 演算子で関数を評価すると function が返ることについて文中で補足する
b. console.log(typeof function() {}); // => "function" の記述を消す
c. function がかえる結果については深追いしないことを文中で明言する

自分で試した読者が混乱する・質問がくると思うので、a が望ましいとは思います。

@azu azu added the Status: Proposal 提案段階の状態 label Aug 14, 2022
@azu
Copy link
Collaborator

azu commented Aug 14, 2022

a. typeof 演算子で関数を評価すると function が返ることについて文中で補足する

関数も ここの流れに入れるのが自然な感じがしますね。
関数もオブジェクトですが、特別扱いされるので、プリミティブとオブジェクト(関数とその他)という感じで

データ型を細かく見ていくと、7つのプリミティブ型とオブジェクトからなります。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Proposal 提案段階の状態
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants