Dux-Courses Evaluaciones
DOCUMENTATIONCOURSESROADMAPRANKINGBLOGPLAYGROUND
LoginSign Up
Aurum-Courses

Aurum Courses is an advanced learning and evaluation platform designed to accelerate your tech career. We provide an immersive environment filled with challenges, technical documentation, and verifyable certificates for frontend, backend, and fullstack technologies.

Platform Links

  • Interactive Courses
  • Technical Documentation
  • Tech Blog & Articles
  • Mi Perfil y Progreso

About the Project

  • About the Project
  • Contact & Support

Legal & Compliance

  • Privacy Policy
  • Terms of Service
  • Cookies Management
© 2026 Aurum-Courses. All rights reserved. Made with passion for the developer ecosystem.

Desarrollado por Aurumdux

Docs/JavaScript/Iteradores y Generadores
Avanzadojavascript

Iteradores y Generadores

Comprende el protocolo iterable de JavaScript y como crear generadores con function*.

El protocolo iterable

Un objeto es iterable si implementa el metodo [Symbol.iterator](). Arrays, Strings, Maps y Sets son iterables nativamente. El bucle for...of funciona sobre cualquier iterable.
javascript
1const texto = "Hola";
2for (const letra of texto) {
3  console.log(letra); // H, o, l, a
4}
5
6const mapa = new Map([["a", 1], ["b", 2]]);
7for (const [clave, valor] of mapa) {
8  console.log(`${clave}: ${valor}`);
9}

Generadores (function*)

Los generadores son funciones que pueden pausar su ejecucion con yield y reanudarla despues. Retornan un iterador.
javascript
1function* fibonacci() {
2  let a = 0, b = 1;
3  while (true) {
4    yield a;
5    [a, b] = [b, a + b];
6  }
7}
8
9const fib = fibonacci();
10console.log(fib.next().value); // 0
11console.log(fib.next().value); // 1
12console.log(fib.next().value); // 1
13console.log(fib.next().value); // 2
14console.log(fib.next().value); // 3

Prueba lo aprendido

Escribe código JavaScript y ejecútalo directamente en el navegador.

Editor de Códigojavascript
1const texto = "Hola";
2for (const letra of texto) {
3  console.log(letra); // H, o, l, a
4}
5
6const mapa = new Map([["a", 1], ["b", 2]]);
7for (const [clave, valor] of mapa) {
8  console.log(`${clave}: ${valor}`);
9}
← AnteriorManejo de Errores