JS-2: Functions & Scope
Functions & Scope
Section titled “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
โครงสร้างบท
Section titled “โครงสร้างบท” 01 — Functions declaration, arrow functions, default params, rest/spread
02 — Scope & Closures block scope, function scope, closures, IIFE
03 — Array Methods map, filter, reduce, find, some, every, forEach, sort
Lab: Data Pipeline สร้าง data pipeline ด้วย array methods
ทำไม Functions สำคัญ?
Section titled “ทำไม Functions สำคัญ?”- Reusability — เขียนครั้งเดียว เรียกใช้ซ้ำได้ตลอด
- Abstraction — ซ่อนรายละเอียดที่ซับซ้อนไว้ภายใน
- Composition — ต่อ function เล็ก ๆ เป็น pipeline ใหญ่ได้
- Testability — function แต่ละตัวทดสอบแยกได้ง่าย
Prerequisites
Section titled “Prerequisites”ก่อนเรียนบทนี้ควรเข้าใจ:
- Variables & types จาก JS-1
- Operators และ control flow พื้นฐาน
- การเปิด browser console เพื่อทดลอง code