What-I-Learned-in-Week-5

Topics we covered in Week-5

  • Mapping

  • Filter

  • For of Loops

  • Objects

  • Objects with Mutations

  • Objects without Mutations

Alt Text

What is Mapping?

  • They always produce a new array
  • They have the same number of elements as the original
  • Each element has been changed in some way

What is a Filter?

  • Only .push some variables into our new array.
  • Only pushing the one's that match our criteria .filter.
  • What's in the for loop is what the difference that get's pushed into the new array.
  • What's our criteria in the if statement, decides what goes in the element.

For-of Loops what are they?

  • So far we have been using [i] to access the value.
  • Now we are able to use a loop access without hitting [i].
  • More efficient and less syntax.

Alt Text

Objects tell us more?

  • Objects are variables too. But objects can contain many values.
  • List about one thing. For example Classic Car and the criteria that define a Classic Car.
  • These are called values.
  • We can also reassign those properties.
  • Changing an existing property and makking a new one.

Objects with Mutations? I'm listening...

  • Objects are mutable in JavaScript.
  • Objects are reference typed data. Therefore, they contains the reference to the value.
  • Once we change that reference point, that's it we have mutated the code.
  • Mutation is a bad programming practice. If your code is mutable, you might change or break something without knowing. The code becomes harder to read and test, produces non-predictable side effects.
  • Is there a better way? Sure is!

Alt Text

Objects without Mutations, the right way.

  • Objects without mutations we are able to change the value without losing the reference value.

  • We essentially are returning a new version.

  • But still able to keep the reference value.

  • Anything we pass in can be changed but still allow to keep that reference value.

  • It's a great way to change a value but always know you'll have that reference value to return too.

  • On to Week-6 šŸ„³