Skip to content

Commit aeaae1c

Browse files
Copilotna-trium-144
andcommitted
Split JavaScript primitive type docs into focused sections
Co-authored-by: na-trium-144 <100704180+na-trium-144@users.noreply.github.com> Agent-Logs-Url: https://github.com/ut-code/my-code/sessions/34fbc605-3a4e-4915-9c25-26c8cf45a082
1 parent 846a889 commit aeaae1c

File tree

6 files changed

+143
-65
lines changed

6 files changed

+143
-65
lines changed

public/docs/javascript/1-basics/2-0-primitive-type.md

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ id: javascript-basics-primitive-type
33
title: 'データ型: プリミティブ型'
44
level: 2
55
question:
6+
- プリミティブ型とは、ざっくり言うとどういう値のことですか?
67
- プリミティブ型がイミュータブル(変更不可)というのは、どういう状態を指しますか?
7-
- String型で「テンプレートリテラル」を使うと、具体的に何が便利になるのですか?
8-
- Number型で整数と浮動小数点数の区別がないというのは、何か問題になることはありますか?
8+
- String / Number / Boolean / undefined / null の詳細はどこで学べますか?
99
- SymbolやBigIntは、通常の開発でどのくらいの頻度で使うものですか?
1010
---
1111

@@ -15,38 +15,12 @@ JavaScriptは動的型付け言語であり、変数は特定の型に紐付き
1515

1616
プリミティブ型はイミュータブル(変更不可)であり、以下の7種類が存在します。
1717

18-
1. **String**: 文字列。ES6から導入された「テンプレートリテラル(バッククォート `` ` ``)」を使うと、変数の埋め込みが容易です。
19-
2. **Number**: 数値。整数と浮動小数点数の区別はなく、すべて倍精度浮動小数点数(IEEE 754)として扱われます。
20-
3. **Boolean**: `true` または `false`
21-
4. **undefined**: 「値が未定義である」ことを表す型。変数を宣言して値を代入していない状態です。
22-
5. **null**: 「値が存在しない」ことを意図的に示す型
23-
6. **Symbol**: 一意で不変な識別子。オブジェクトのプロパティキーなどに使われます。
24-
7. **BigInt**: `Number`型では表現できない巨大な整数を扱います(末尾に `n` をつけます)。
18+
1. **String**: 文字列
19+
2. **Number**: 数値
20+
3. **Boolean**: `true` または `false`
21+
4. **undefined**: 「値が未定義である」ことを表す型
22+
5. **null**: 「値が存在しない」ことを意図的に示す型
23+
6. **Symbol**: 一意で不変な識別子(主にオブジェクトのプロパティキー用途)
24+
7. **BigInt**: `Number`型では表現できない巨大な整数を扱う型(末尾に `n`
2525

26-
```js-repl
27-
> // String: シングルクォートまたはダブルクォートで囲む
28-
> const language = "JavaScript";
29-
undefined
30-
> language
31-
'JavaScript'
32-
> // テンプレートリテラル(バッククォート)を使うと変数を文字列に埋め込める
33-
> const version = 2015;
34-
undefined
35-
> `${language} ES${version}`
36-
'JavaScript ES2015'
37-
> // Number: 整数も小数も同じ型
38-
> const price = 1980;
39-
undefined
40-
> const tax = 0.1;
41-
undefined
42-
> price * (1 + tax)
43-
2178.0000000000002
44-
> // Boolean
45-
> const isActive = true;
46-
undefined
47-
> typeof isActive
48-
'boolean'
49-
> // BigInt: 末尾に n をつける
50-
> 9007199254740991n + 1n
51-
9007199254740992n
52-
```
26+
この章では、まず最もよく使う `String` / `Number` / `Boolean` / `undefined` / `null` を順に見ていきます。`Symbol``BigInt` は用途が限定的なため、ここでは「プリミティブ型の一種」であることだけ押さえれば十分です。

public/docs/javascript/1-basics/2-1-null-undefined.md

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
id: javascript-basics-string
3+
title: 文字列(String)
4+
level: 3
5+
question:
6+
- シングルクォートとダブルクォートで文字列を囲むことの違いは何ですか?
7+
- テンプレートリテラルは、どんな場面で使うと便利ですか?
8+
- テンプレートリテラルの `${}` の中に計算式を書けますか?
9+
---
10+
11+
### 文字列(String)
12+
13+
JavaScriptの文字列は、シングルクォート (`'`) またはダブルクォート (`"`) で作成します。
14+
15+
また、バッククォート (`` ` ``) で囲む**テンプレートリテラル**を使うと、変数や式を文字列に埋め込めます。文字列の連結(`+`)より読みやすくなることが多いため、こちらを使うのが一般的です。
16+
17+
```js-repl
18+
> const name = "Ada";
19+
undefined
20+
> const language = 'JavaScript';
21+
undefined
22+
> // + で連結
23+
> "Hello, " + name + "!"
24+
'Hello, Ada!'
25+
> // テンプレートリテラルで埋め込み
26+
> `Hello, ${name}!`
27+
'Hello, Ada!'
28+
> // 式も埋め込める
29+
> `${language}は${10 + 5}日で入門できます`
30+
'JavaScriptは15日で入門できます'
31+
```
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
id: javascript-basics-number
3+
title: 数値(Number)
4+
level: 3
5+
question:
6+
- JavaScriptで整数と小数を区別しないのは、どういう意味ですか?
7+
- 除算や剰余など、基本的な計算はどのように書けば良いですか?
8+
- 小数計算で誤差が出ることがあるのはなぜですか?
9+
---
10+
11+
### 数値(Number)
12+
13+
JavaScriptの数値は `Number` 型で表され、**整数と小数を区別しません**。どちらも同じ `number` として扱われます。
14+
15+
四則演算は直感的に行えます。べき乗は `**`、剰余は `%` を使います。
16+
17+
```js-repl
18+
> const a = 10; // 整数
19+
undefined
20+
> const b = 3.14; // 小数
21+
undefined
22+
> typeof a
23+
'number'
24+
> typeof b
25+
'number'
26+
> 10 + 3
27+
13
28+
> 10 / 3
29+
3.3333333333333335
30+
> 10 % 3
31+
1
32+
> 2 ** 4
33+
16
34+
> 0.1 + 0.2
35+
0.30000000000000004
36+
```
37+
38+
`0.1 + 0.2` のような小数計算で誤差が出るのは、JavaScriptが数値を内部的に2進数の浮動小数点として扱うためです。
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
id: javascript-basics-boolean
3+
title: 真偽値(Boolean)
4+
level: 3
5+
question:
6+
- Boolean型はどんな場面で使いますか?
7+
- 論理演算子 `&&` と `||` と `!` の基本を教えてください。
8+
- '`true` / `false` は文字列の `"true"` / `"false"` と何が違いますか?'
9+
---
10+
11+
### 真偽値(Boolean)
12+
13+
真偽値は `true``false` の2つの値を持ちます。条件分岐や判定処理で使う基本的な型です。
14+
15+
論理演算子には、AND(`&&`)、OR(`||`)、NOT(`!`)があります。
16+
17+
```js-repl
18+
> const isActive = true;
19+
undefined
20+
> const hasPermission = false;
21+
undefined
22+
> typeof isActive
23+
'boolean'
24+
> // AND: 両方 true なら true
25+
> isActive && hasPermission
26+
false
27+
> // OR: どちらかが true なら true
28+
> isActive || hasPermission
29+
true
30+
> // NOT: true/false を反転
31+
> !isActive
32+
false
33+
```
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
id: javascript-basics-undefined-null
3+
title: undefined と null
4+
level: 3
5+
question:
6+
- undefinedとnullは、どう使い分けるのが良いですか?
7+
- 変数を宣言しただけの状態がundefinedになるのはなぜですか?
8+
- '`typeof null` が `''object''` になるのは本当に正しいのですか?'
9+
---
10+
11+
### undefined と null
12+
13+
他言語経験者が最初に混乱しやすいのが、この `undefined``null` の違いです。
14+
15+
- **undefined**: JavaScriptエンジンが「値がまだない」ことを示すときに現れます(例: 宣言だけして代入していない変数)。
16+
- **null**: プログラマが「ここには値がない」と明示したいときに代入します。
17+
18+
```js-repl
19+
> let unassigned;
20+
undefined
21+
> unassigned
22+
undefined
23+
> let empty = null;
24+
undefined
25+
> typeof unassigned
26+
'undefined'
27+
> typeof empty
28+
'object'
29+
```
30+
31+
`typeof null``'object'` になるのは、JavaScript初期から残っている歴史的な仕様です。`null` 自体はオブジェクトではなく、プリミティブ型の値です。

0 commit comments

Comments
 (0)