0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

JavaScriptの基礎(3)

Posted at

※この記事は初学者の毎日のアウトプット用に作成している記事です

データ型

JavaScriptには8つの型がある
7つのプリミティブ型と1つのオブジェクト型が存在する

プリミティブ型

null型 ー 値がない
undefined型 ー 値が定義されていない
Boolean型 ー 真偽値
Number型 ー 数値
Biglnt型 ー Numberよりも大きいor小さい数を扱う
String型 ー 文字列
Symbol型 ー シンボル

オブジェクト型

オブジェクト型 ー 関連するデータなどをまとめたもの

違い

プリミティブ型のデータが代入されている変数には値そのものが保存されているが、オブジェクト型のデータが代入されている変数には値が保存されているメモリーの場所が保存される

// プリミティブ型 (number)
let a = 10;
let b = a; // 値がコピーされる (値そのものを代入)

// 値を書き換える
b = 20;

console.log(a); // 10 (aの値には影響なし)
console.log(b); // 20

// オブジェクト型
let obj1 = { value: 10 };
let obj2 = obj1; // メモリのアドレスがコピーされる (参照が渡される)

// 値を書き換える
obj2.value = 20;

console.log(obj1.value); // 20 (obj1の値も影響を受ける)
console.log(obj2.value); // 20


参考書籍:

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?