Javascript Week 5 — Fake classes

Ben Baron
2 min readFeb 28, 2021

Describe one thing you’re learning in class today. Why do you think it will be important in your future web development journey?

Classes! They’ll be important because it saves an incredible amount of time when making objects with the same parameters. I can see this being exceedingly useful when making websites that log users and any sort of data in general.

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

Personally, I find that arrow function syntax is easier to read that other function syntaxes, so I may start using them more for that single reason.

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

As stated above, I personally find the the style of the arrow function is simply easier to read. Functionally, the arrow function syntax is anonymous and changes how this works with the function.

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

function foo() {} just creates a function called “foo”, while const foo = function() {} creates a variable that hold the function called “foo”.

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

It changes how this binds with the object, allowing you to bypass the object’s properties. This is helpful when using callback functions or methods such as forEach or map.

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

If you have arr = [1, 2, 3], you could then say let [x, y] = arr. This would set x = 1, and y = 2.

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.

When a function is called, a closure is created, and everything within the function is accessible to everything else within that same function. This can be used when calling api’s, using then. to access the package that was received initially.

--

--