Class 10 — Prompt 205

Amanda Rush
2 min readJul 30, 2021
  1. Describe one thing you’re learning in class today. Why do you think it will be important in your future web development journey?

We are learning about creating classes and having them interact with each other. We also learned about creating subclasses and how they can have access to the properties and methods of the parent class. I think this will come in handy with future web development because it helps to group concepts into separate modules or components while keeping their functionality grouped together.

2. Can you offer a use case for the new arrow => function syntax?

You would want to use arrow functions when you want the “this” keyword to be bound to the containing parent object. Arrow functions also simplify syntax and can make the function easier to read and understand what it is doing.

3. How does this new syntax differ from the older function signature, function nameFunc(){}, both in style and functionality?

If arrow functions are short and only have one line of logic they can be condensed to a single line of code where the parentheses around the parameter can be omitted if there is only one parameter and the return can be omitted if the function is only returning a single value without other logic written.. Older functions cannot do that. They have to be written with parentheses and a return.

4. Explain the differences on the usage of foo between function foo() {} and const foo = function() {}

Function foo() is a function declaration, whereas const foo = function() {} is a function expression. Function declarations are evaluated before the other code is executed line by line. Function expressions are evaluated during the line by line execution with the rest of the code. It creates an anonymous function which is assigned to the variable foo.

5. What advantage is there for using the arrow syntax for a method in a constructor?

The biggest advantage is that the “this” keyword gets set when the function is created and doesn’t change. When the constructor creates a new object, the “this” keyword will always refer to that object. On the other hand, when you use a normal function you would need to bind “this” in the constructor.

6. Can you give an example for destructuring an object or an array?

7. Explain Closure in your own words. How do you think you can use it? Don’t forget to read more blogs and videos about this subject.

Closures are functions that are passed to other functions as a callback function. They are handy when they need to have access to the enclosing functions variables. Higher order functions use closures as callbacks.

--

--