Prompt 205

Sandra Escalante
2 min readJun 16, 2021

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 Object.create() which allows us to create objects with more attribute options like configurable, enumerable, writable and value. It will be important to be able to use this because it will helps when working with API’s.

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

The new arrow allows you to omit the curly braces and the return statement due to implicit returns.

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

function nameFunc( ) { }; vs const nameFunc = ( ) => { }; Although, the arrow function may be shorter code, it cannot use the keyword this. In regular functions the this keyword represented the object that called the function, which could be the window, the document, a button or whatever. With arrow functions the this keyword always represents the object that defined the arrow function.

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

function foo ( ) { } is creating a new function that can possibly take in parameters (arguments). Const foo = function ( ) { } is creating a variable that is equal to a function.

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

The introduction of arrow functions, sometimes called ‘fat arrow’ functions, utilize the new token =>. These functions have two major benefits — a very clean concise syntax and more intuitive scoping and this binding.

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

const movie = {
title: 'Star Wars',
releaseDate: 'May 25, 1977',
country: 'United States',
};

If we want to pull individual values from this object, we could do this: const title = movie.title

Or, using the destructuring syntax we could do this instead: const {title, country} = movie
console.log(title, country) // ‘Star Wars’, ‘United States’

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.

A closure is the combination of a function bundled together (enclosed) with references to its surrounding state.
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. Closures are useful because they let you associate data (the lexical environment) with a function that operates on that data.
This has obvious parallels to object-oriented programming, where objects allow you to associate data (the object’s properties) with one or more methods. Consequently, you can use a closure anywhere that you might normally use an object with only a single method.

--

--