Skip to content

JS-3: 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

ทำไมต้องเรียน 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 ยังทำงานไม่เสร็จ