So much coding is making me loopy.
Describe one thing you’re learning in class today.
The this
keyword is one way to make your JS code more versatile and modular when dealing with objects that have the same keys. It is used inside a method to refer to the object which is currently being used. For example, take this code below:
const practiceWithThis = () => {
console.log(this.name)
}
const user1 = {name:'Greg', age: 33};
const user 2 = {name:'Susan', age: 54};
user1.practiceWithThis() // 'Greg'
user2.practiceWithThis() // 'Susan'
You can easily see here how we can use a function to access a user’s name with multiple user objects.
What’s the difference between: function Person(){}
, var person = Person()
, and var person = new Person()
?
function Person(){}
is an object, var person = Person()
is a variable assigned to a function, and var person = new Person()
is a constructor.
What’s the difference between an “attribute” and a “property”?
Attributes are assigned in the HTML then parsed by the browser to create DOM elements where these attributes are accessible just like JS properties. For example if the HTML tag is: <main id=“mainContent”>
, then main.id = “mainContent”
.
- What language constructions do you use for iterating over object properties and array items?
Object: for loop, for..in, for each..in, Object.keys(), map, reduce etc.
Array: for, forEach, for…of
What is the event loop? What is the difference between call stack and task queue?
The event loop is what allows JS to be asynchronous. First you have the call stack which basically starts at the top of the JS file and starts stacking each action to perform (such as a function) in the order that they are read. The event loop keeps track of the call stack and anything in the task queue. When the call stack is empty anything in the task queue is added to the call stack and executed.
This video does an excellent job of describing the even loop and how JS works: https://www.youtube.com/watch?v=8aGhZQkoFbQ&feature=emb_logo
What are the differences between ES6 classes and ES5 function constructors?
The biggest difference between these two is how they deal with inheritance. Each instantiates objects differently and also the this
keyword may refer to different things in each case.