Skip to content
This repository has been archived by the owner on Apr 23, 2022. It is now read-only.

Latest commit

 

History

History
78 lines (46 loc) · 3.93 KB

File metadata and controls

78 lines (46 loc) · 3.93 KB

Lesson 7: built-ins

If some of the built-ins in lesson 7 were new to you, we hope the following links will help you.

<= GO BACK

Resource links

Iterable & Iterator Protocols

The Iterable Protocol

The iterable protocol is used for defining and customizing the iteration behavior of objects. What that really means is you now have the flexibility in ES6 to specify a way for iterating through values in an object. For some objects, they already come built-in with this behavior. For example, strings and arrays are examples of built-in iterables.

Udacity quote

The Iterator Protocol

The iterator protocol is used to define a standard way that an object produces a sequence of values. What that really means is you now have a process for defining how an object will iterate. This is done through implementing the .next() method.

Udacity quote


A WeakSet is just like a normal Set with a few key differences:

  • a WeakSet can only contain objects
  • a WeakSet is not iterable which means it can’t be looped over
  • a WeakSet does not have a .clear() method

Garbage Collection

In JavaScript, memory is allocated when new values are created and is "automatically" freed up when those values are no longer needed. This process of freeing up memory after it is no longer needed is what is known as garbage collection.

WeakSets take advantage of this by exclusively working with objects. If you set an object to null, then you’re essentially deleting the object. And when JavaScript’s garbage collector runs, the memory that object previously occupied will be freed up to be used later in your program.

Udacity quote


A WeakMap is just like a normal Map with a few key differences:

  • a WeakMap can only contain objects as keys,
  • a WeakMap is not iterable which means it can’t be looped and
  • a WeakMap does not have a .clear() method.

Garbage Collection

In JavaScript, memory is allocated when new values are created and is "automatically" freed up when those values are no longer needed. This process of freeing up memory after it is no longer needed is what is known as garbage collection.

WeakMaps take advantage of this by exclusively working with objects as keys. If you set an object to null, then you’re essentially deleting the object. And when JavaScript’s garbage collector runs, the memory that object previously occupied will be freed up to be used later in your program.

Udacity quote