Problem Domain, Objects, and the DOM
JavaScript Object Basics
- How would you describe an object to a non-technical friend you grew up with?
An object is like a cabinet with a bunch of little drawers. You can put anything in these drawers. You can also really easily organize and find the items you have stored.
- What are some advantages to creating object literals?
It is easier to organize information this way. They can be used to store anything and be called later on. They can be used to even call different function within the object, which are called methods.
- How do objects differ from arrays?
They both are a container for other variables, and they both can house each other. Some differences so are they way you access the data within them. In an array you use the index of the value you want, while in a an object you use the dot notation or the bracket notation. Objects can also be used to store functions in the form of methods, while arrays cannot.
- Give an example for when you would need to use bracket notation to access an object’s property instead of dot notation.
If you need to access the property by a variable, lets say an input from a user, then you might need to access the property using the bracket notification because it uses a string.
- 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
is a call to properties that are part of this
object and can be used within other properties or methods.
Introduction To The DOM
- What is the DOM?
DOM drives the dynamic expression of the HTML. This is a built in API allows us to dynamically change what is seen through a web browser.
- Briefly describe the relationship between the DOM and JavaScript.
DOM is the set of functions that are pert of JavaScript that allow for the control/printing of HTML elements using JavaScript.
Things I want to know more about