JS-3: Objects & Async
Objects & Async
Section titled “Objects & Async”บทนี้ครอบคลุมสองหัวข้อสำคัญ: Objects ซึ่งเป็น data structure หลักของ JavaScript และ Asynchronous programming ที่จำเป็นสำหรับการทำงานกับ API
เป้าหมายการเรียนรู้
Section titled “เป้าหมายการเรียนรู้”- สร้างและจัดการ objects ด้วย destructuring, spread และ optional chaining
- เข้าใจ Promises และเขียน async/await ได้
- ใช้ fetch() ดึงข้อมูลจาก API ได้
- จัดการ errors ด้วย try/catch/finally อย่างเหมาะสม
Progress 0 / 4
โครงสร้างบท
Section titled “โครงสร้างบท” 01 — Objects object literals, destructuring, spread, computed properties, optional chaining
02 — Async Programming callbacks, Promises, async/await, fetch()
03 — Error Handling try/catch/finally, custom errors, error boundaries
Lab: Fetch API ดึงข้อมูลจาก API จริงและจัดการ errors
ทำไมต้องเรียน Async?
Section titled “ทำไมต้องเรียน Async?”แทบทุกอย่างใน web development เป็น async:
- Fetch data จาก REST API หรือ GraphQL
- อ่านไฟล์ จาก disk (Node.js)
- รอ user input เช่น click, form submit
- Timer เช่น setTimeout, setInterval
ถ้าไม่เข้าใจ async จะเจอ bug ที่ data เป็น undefined เพราะ code ยังทำงานไม่เสร็จ