1 ใน 40 สิ่งจำเป็นของ Javascript- ประเภทข้อมูล
ในการเป็น Front Developer ที่ประสบความสำเร็จ จำเป็นต้องมีพื้นฐาน Javascript ที่แข็งแกร่ง ชุดนี้พยายามครอบคลุมแนวคิดที่สำคัญทั้งหมดของภาษา
อย่างไรก็ตาม ฉันมี Instagram Reel และ Youtube Short ในบทความนี้ หากคุณต้องการ โปรดคลิกที่นี่: Data types — Insta Reel , Data types — Youtube Short .
ภาษาโปรแกรมทั้งหมดมีโครงสร้างข้อมูลในตัว แต่ภาษาเหล่านี้มักแตกต่างจากภาษาหนึ่งไปอีกภาษาหนึ่ง บทความนี้จะอธิบายทั้งประเภทข้อมูลดั้งเดิมและไม่ใช่ข้อมูลดั้งเดิมใน Javascript
ประเภทข้อมูลดั้งเดิม
ในJavascriptประเภทดั้งเดิมถูกกำหนดล่วงหน้าโดยภาษาและเป็นข้อมูลที่ไม่ใช่วัตถุและมีเมธอดหรือคุณสมบัติ มี 7 ประเภทดั้งเดิมใน Javascript
- สตริง
- ตัวเลข
- ไม่ได้กำหนด
- บิ๊กอินท์
- บูลีน
- สัญลักษณ์
- โมฆะ
- สตริง — A
stringคือลำดับของอักขระตั้งแต่หนึ่งตัวขึ้นไป ซึ่งอาจประกอบด้วยตัวอักษร ตัวเลข หรือสัญลักษณ์ และออบเจกต์นี้จะพันรอบสตริงดั้งเดิม
// string in JS
name = "Toronto Dev"
// Number
x = 5
y = 12
z = 12.4
console.log(x) // Output to web console: undefined.
// Boolean in JS
isOn = true
isStart = false
// null value
let x = null;
console.log("Value of x" + x)
// BigInt
let number = BigInt(565656565656565656656565656565656565634)
// Symbol value
let symbol1 = Symbol()
let symbol1 = Symbol('baz')
let symbol1 = Symbol('baz')
// We replaced the value of string primitive variable
let string = "who invented World Wide Web"
string = 'Sir Tim Berners-Lee'
// However, We cannot ALTER only REPLACE, like the example below.
let string = 'Sir Tim Berners-Lee'
string[0] = 's' // Outpust -> 'Sir Tim Berners-Lee'
ชนิดข้อมูลที่ไม่ใช่ข้อมูลพื้นฐานมาจากค่าดั้งเดิม หรือที่เรียกว่าderived data typeหรือreferenced data type.
- วัตถุ — ใน Javascript วัตถุเป็นเอนทิตีแบบสแตนด์อโลนที่มีคุณสมบัติและประเภท
// Creating an object with name person
let person = {
firstName: "Toronto",
lastName: "Dev",
};
console.log(`${person.firstName} ${person.lastName}`)
// Empty array
let x = new array()
// Array with single numeric argument
let y = new array(10)
// Explicit values
let z = new Array(1, 3, "Toronto")
let arr = ['Toronto', 'Melbourne', 'New Delhi']
// We are mutating the state of variable arr using index
arr[1] = 'Sydney'
typeof "G`day" // string
typeof 0 // number
typeof null // object
typeof 1n // BigInt
typeof true // boolean
typeof undefined // undfined
typeof Symbol("id") // symbol
typeof {} // object
ฉันหวังว่าฉันได้เพิ่มสิ่งใหม่ให้กับความรู้ของคุณในเรื่องนี้ แล้วพบกัน ใหม่ บทความที่ 2ของซีรีย์นี้ครับ
โซเชียล:
- ช่อง Youtube ของโตรอนโตเดฟ
- หน้า Instagram ของโตรอนโตเดฟ





































![รายการที่เชื่อมโยงคืออะไร? [ส่วนที่ 1]](https://post.nghiatu.com/assets/images/m/max/724/1*Xokk6XOjWyIGCBujkJsCzQ.jpeg)