Objects and garbage collection was today’s topic. Also some more experimenting happened today. The new experiment was making flash cards to memorize definitions and syntaxes.
A property is a “key: value” pair, where
key is a string (also called a “property name”), and
value can be anything.
I liked the example being referred to as a key being into crypto keys are a keyword. Anything can be an object, but if it’s multiple words it has to be in quotes.
Objects are assigned and copied by reference. In other words, a variable stores not the “object value”, but a “reference” (address in memory) for the value. So copying such a variable or passing it as a function argument copies that reference, not the object. All operations via copied references (like adding/removing properties) are performed on the same single object.
Garbage collection is performed automatically. When objects are not reachable they are deleted. As mentioned before when objects are saved in reference they are saved in memory. However, reference is not equivalent to reachability. As long as the root is not reachable all of the other references are invalid and unreachable. The root is the first thing referenced.