InterviewHubPRO
Section Overview
Q424

Question 424 of 521

Part 7: Execution Context, Functional JS & V8 Engine (404 - 463)

81%
JavaScript Internals (521 Qs)•Part 7: Execution Context, Functional JS & V8 Engine (404 - 463)

What are the built-in iterables

Below are the list of built-in iterables in javascript,

  1. Arrays and TypedArrays
  2. Strings: Iterate over each character or Unicode code-points
  3. Maps: iterate over its key-value pairs
  4. Sets: iterates over their elements
  5. arguments: An array-like special variable in functions
  6. DOM collection such as NodeList

Practical Code Example

javascript
// Built-in Iterables implementing [Symbol.iterator]:
const array = [1, 2, 3];
const string = "hello";
const map = new Map([['a', 1]]);
const set = new Set([1, 2, 3]);

for (const char of string) console.log(char); // Iterates 'h', 'e', 'l', 'l', 'o'