BlogPost_205
- Describe one thing you're learning in class today.
- In class we don´t learn. We learn by googling and finding answers ourselves. In class I´m learning how not to rely on class to learn. In class we just beg the teachers to give us the answers to the assignments we have since we have not learned anything there and we can´t solve them ourselves. It´s great practice since it doesn´t create dependability and promotes independent thinking. I googled and learned about objects.
- Can you offer a use case for the new arrow
=>function syntax? How does this new syntax differ from other functions? - You can use the arrow function when you want to quickly make an anonymous function or when you want to reduce the amount of code you´re using.
- The new syntax differs from other functions in the sense that certain scopes will work differently with the => function. You would also need to attach the function to a variable in order to call it.
- Explain the differences on the usage of
foobetweenfunction foo() {}andvar foo = function() {} One is a function called foo. The other one is a declaration of a variable that contains a function.They have different scopes and evaluated at different times.
- Can you give an example for destructuring an object or an array?
| const student = { | |
| firstname: 'Glad', | |
| lastname: 'Chinda', | |
| country: 'Nigeria' | |
| }; | |
| // Object Destructuring | |
| const { firstname, lastname, country } = student; | |
| console.log(firstname, lastname, country); // Glad Chinda Nigeria |
- What advantage is there for using the arrow syntax for a method in a constructor?
- Constructors
There’s another way arrow functions don’t work well with objects. They can’t be constructors. The classic function expressions can be used to construct a new object like so:
let Person = function(name, height) { this.name = name this.height = height }Person.prototype.hello = function() { console.log('Hi, my name is ' + this.name) }let alice = new Person('Alice', 1.7) alice.hello() // Hi, my name is Alice
But arrow functions do not have a
prototype property and they cannot be used with new.- Explain Closure.
- A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment). In other words, a closure gives you access to an outer function’s scope from an inner function. In JavaScript, closures are created every time a function is created, at function creation time.

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home