UNDERSTAND JAVASCRIPT FUNCTIONS IN DEPTH - JavaScript Fundamentals.

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 พ.ย. 2024
  • Learn Functions the right way : Function expression, return, undefined, common mistakes and lots of examples

ความคิดเห็น • 1

  • @devafterdark
    @devafterdark ปีที่แล้ว

    didn't mention closure scope, it allows you to have private member variables in javascript:
    const Counter = () => {
    let count = 0;
    return {
    incrementCount: () => count++,
    getCount: () => count
    }
    }
    const counter = Counter();
    console.log(counter.getCount()); // 0
    counter.incrementCount();
    console.log(counter.getCount()); // 1
    the count member variable of the function Counter is not accessible outside of the function scope, but it's value is still kept in memory because the object returned from counter still references it, and is the only way to access count. The garbage collector does NOT free resources that are still referenced. proper OOP hehe