March 04, 2019
Today's lessons were quite useful and covered JS data types and the DOM.
There are two categories of data types in JS:
- Objects (can be as complex as you want)
- E.g. Objects, Arrays, Functions,
- Primitives (building blocks of JS)
- Undefined // value that hasn’t been set
- Null // ‘nothing’
If it's not a primitive, it's an object.
Primitive Comparisons vs Object Comparisons:
When you create an object in JS, it actually creates a unique location in memory.
When comparing primitives, JS is comparing the values.
When comparing objects, JS is comparing the references (memory addresses).
For objects, JS doesn’t care that the values look the same, it’s irrelevant – what it actually cares about is if the addresses are the same
When primitives are assigned to a variable, the value is stored.
When objects are assigned to a variable, the reference/memory address is stored.
What is the DOM?
The DOM is what the browser understands the HTML document to be. The browser will use the information in your HTML to build an understanding of this document looks like. The browser's interpretation of your HTML is the DOM tree.Event Listeners
Event listeners listen for specified ‘events’ (eg. mouse click) and runs the specified event handler function each time the event occurs
If you have DOM interactions in your JS file, you need to put your
<script> tag right before the closing