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.

I really want to hammer in fundamentals of JavaScript, because it plays a huge role into front end development. Once I know JavaScript and it’s libraries I will be confident to get a front end developer job.

On to today’s lesson, objects I really like how it was explained on JavaScript.info. It is one of the seven data types and is opened with curly braces {} with a property. The example I liked was about the optional property you can add.

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.

Leave a comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: