Two more weeks left…

Taylor Cannetti
2 min readNov 1, 2020

All caught up on my interview practice questions! Now to stay on top of them all and try and solidify what I learn each week by doing these after I finish the homework assignments.

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 continuing to dive into Object Oriented Programming, and more specifically classes. This is our 3rd class about classes, and how we can use them to create new objects when necessary. This seems useful for multiple reasons, but since classes were just added to ES6 it’s obvious they are a solution to a pain-point of many developers in the past.

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

It seems that in most cases it’s better at creating clean concise code. Using the D.R.Y. approach it can let you accomplish more with less code. The issues that arise with the fat arrow syntax come up when using Classes and creating a new object of that class. Arrow functions do not work in this instance and you must use older function syntax.

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

You immediately get to remove the word ‘function’:

let add = function(x,y) { 
return x + y; }

Becomes:

let add = (x,y) => x + y;

Again, cleaner more concise code, however there are tradeoffs where Javascript won’t understand what you are trying to do unless you implicitly tell it. For example, expressions no longer require curly brackets within the body of an arrow function, but statements do.

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

function foo(){} is creating a function named food without a defined parameter.

const foo = function(){}, is creating an undefined variable that will return whatever is in the parenthesis of the function.

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

After a lot of reading, everyone said not to do it. I’ll bring this up in the next class.

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

let a, b;

[a, b] = [1, 2];
console.log(a); // 1
console.log(b); // 2

Explain Closure in your own words. How do you think you can use it?

A closure is a function enclosed within another function that gives it access to the outer functions scope from within the inner function. Closures are created every time a function is created, at the functions creation time. You can use a closure by defining a function within another function and exposing, return or pass it to another function, it.

--

--