Module Patterns
Hey, I was reading about:
https://dev.to/tomekbuszewski/module-pattern-in-javascript-56jm
Code snippet:
Why do we get
timesRun zero, shouldn't it be 1? why is the public value different, im in a position to just "know" but cant explain this very well8 Replies
Because
timesRun is what’s called a primitive value, so when you’re returning your object it’s making a copy of the number 0. You want to, instead, include a function that returns the current value instead.oh
its the pass by reference and value thing
right?
Yep
i see
and why is it primitive 😃
MDN Web Docs
Primitive - Glossary | MDN
In JavaScript, a primitive (primitive value, primitive data type) is data that is not an object and has no methods or properties. There are 7 primitive data types:
Because it’s not an object
ok its int
alright
thank you
