Skip to content

JS-2: Functions & Scope

Functions เป็น building block หลักของ JavaScript — ทุกอย่างตั้งแต่ event handler ไปจนถึง API route ล้วนเป็น function

เป้าหมายการเรียนรู้

Section titled “เป้าหมายการเรียนรู้”
  • เขียน function declaration และ arrow function ได้
  • เข้าใจ scope chain, block scope และ closures
  • ใช้ rest/spread operator ได้อย่างคล่องแคล่ว
  • ใช้ array methods (map, filter, reduce) แทน manual loops ได้
Progress 0 / 4
  • Reusability — เขียนครั้งเดียว เรียกใช้ซ้ำได้ตลอด
  • Abstraction — ซ่อนรายละเอียดที่ซับซ้อนไว้ภายใน
  • Composition — ต่อ function เล็ก ๆ เป็น pipeline ใหญ่ได้
  • Testability — function แต่ละตัวทดสอบแยกได้ง่าย

ก่อนเรียนบทนี้ควรเข้าใจ:

  • Variables & types จาก JS-1
  • Operators และ control flow พื้นฐาน
  • การเปิด browser console เพื่อทดลอง code