reading-notes

Reading 6 - Problem Domain, Objects, and the DOM

JavaScript Object Basics

Source

Q1 How would you describe an object to a non-technical friend you grew up with?

And object is a packet of data (and, optionally, functionality) that has properties in the form of key:value pairs. For example, a car could be like an object in that it has a property of the color red and another property that is the manufacturer Toyota. This would be written out in JavaScript as:

let car = { color: red, manufacturer: Toyota}

Q2 What are some advantages to creating object literals?

  1. It’s most efficient when you’re working with a single object

  2. It is easier to work with than an array, when you want to identify individual items by name

Q3 How do objects differ from arrays?

Objects are unordered, the properties don’t have indices.

They also have a key:value pair, where arrays have an index:value, where the index is always the order of the array (starting at 0)

Q4 Give an example for when you would need to use bracket notation to access an object’s property instead of dot notation.

You would need to use bracket notation if an object property name is held in a variable, then you can’t use dot notation to access the value, but you can access the value using bracket notation.

Q5 Evaluate the code below. What does the term this refer to and what is the advantage to using this?

const dog = { name: ‘Spot’, age: 2, color: ‘white with black spots’, humanAge: function (){ console.log(${this.name} is ${this.age*7} in human years); } }

“This” refers to the current object the code is being written inside. The advantage to using “this” is that you can use the same method definition for each object that you create.

Introduction to the DOM

Source

Q6 What is the DOM?

The DOM is the Document Object Model. It is how the objects that make up the content and structure of a document are represented.

Q7 Briefly describe the relationship between the DOM and JavaScript.

The DOM (Document Object Model) and JavaScript are two crucial parts of making a web site. The DOM is like a map of a web page’s structure, where each element (like text, images, buttons) is represented as objects that can be manipulated.

JavaScript is one of many the programming languages that allows you to interact with this map (the DOM). You can use JavaScript to change the content, style, and behavior of a web page by accessing and modifying these DOM objects. JavaScript and the DOM work together to make web pages interactive and responsive.

Things I want to know more about: