es6 features and fundamentals
3 min readAug 3, 2020
- Describe one thing you’re learning in class today. Why do you think it will be important in your future web development journey?
today i learned how Objects really work in JavaScript, in detail. for example, every object has a __proto__, which is basically the parent object that is delegated to any given object. this __proto__ (an object’s prototype) property is where an object delegates certain methods so that every JS object isn’t bogged down with redundant methods. and if i recall correctly, JS will reach back to each __proto__ until it finds whatever method it’s searching for, before it dead-ends at the “window” object, which is basically God in DOM terms. - Can you offer a use case for the new arrow => function syntax?
How does this new syntax differ from the older function signature, function nameFunc(){}, both in style and functionality?
arrow functions shine when using callback functions or methods that use callback functions (because they are a more concise and clean way of writing out such methods). the classic function signature is better suited for object methods. the reason for this is the way that “this” works. “this” is usually scoped to its object context, but arrow functions only care about the scope in which they’re defined, ignoring their object’s identity. this means that using “this” on an arrow function will possibly result in the global object scope being invoked instead of the lexical scope of a given object. - Explain the differences on the usage of foo between function foo() {} and const foo = function() {}
the first one is a function declaration and the second one is a named function expression. the difference is the variable (function expressions use variables, i.e. const foo = function() {}, because we are expressing a variable equal to something). starting with the function keyword means the function is merely being declared without first expressing its value (its value is the function itself). the difference in utility is that function declarations are hoisted (ran before any other code runs) and expressions are not, but perhaps even more importantly, they maintain closure. - What advantage is there for using the arrow syntax for a method in a constructor?
i’m not really sure about this one, because it would seem that if you used arrow syntax to create a method with the keyword this then it would refer to the global object instead of the constructor. or maybe that itself is the reason to do it, if you’re into that sort of thing. - Can you give an example for destructuring an object or an array?
destructuring assignment has many really neat uses that i’m still trying to wrap my head around, but one very practical one is the ability to push the items of an array into another array as individual items (instead of pushing the array itself into another array). - 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.
closure is the ability of functions to block out “noise” from the global scope (i.e. your code i.e. anything not inside the function). a better question is how NOT to use it, since it’s pretty unavoidable unless you use var.