Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/HotCode2025/Print-Estoy-Cansado-Jefe-TercerSemestre/llms.txt

Use this file to discover all available pages before exploring further.

Arrow functions (=>) were introduced in ES6 as a concise alternative to the traditional function keyword. They quickly became the default choice for callbacks and functional programming patterns in modern JavaScript because they are shorter to write, eliminate boilerplate, and — crucially — they do not create their own this binding. This makes them far more predictable inside class methods, event handlers, and higher-order functions like map, filter, and reduce.

The Four Arrow Function Variants

Every arrow function is built around the same => operator, but the syntax flexes depending on the number of parameters and whether the body is a single expression or a full block.
// Zero parameters: use empty parentheses ()
let miFuncionFlecha = () => {
    console.log('Saludos desde mi funcion flecha');
}

miFuncionFlecha();
// → Saludos desde mi funcion flecha
When an arrow function returns an object literal, wrap the object in parentheses so the parser does not mistake the braces for a block body:
funcionFlecha-3.js — returning an object literal
const regresaObjeto = () => ({ nombre: 'Juan', apellido: 'Lara' });

console.log(regresaObjeto());
// → { nombre: 'Juan', apellido: 'Lara' }

Variant Summary

VariantSyntaxParentheses required?Braces required?return required?
No parameters() => expr✅ Yes❌ No (single expr)❌ No
One parameterparam => expr❌ Optional❌ No (single expr)❌ No
Multiple parameters(a, b) => expr✅ Yes❌ No (single expr)❌ No
Block body(a, b) => { ... }✅ Yes✅ Yes✅ Yes

Implicit Return

When the function body is a single expression (no curly braces), the result of that expression is returned automatically — this is called an implicit return.
1

Start with a classic function expression

classic function expression
const saludar2 = function() {
    return 'Saludos desde la funcion flecha dos';
}

console.log(saludar2());
// → Saludos desde la funcion flecha dos
2

Convert to an arrow function with a block body

Replace function() with () =>. The body and explicit return are still there.
arrow with block body
const saludar2 = () => {
    return 'Saludos desde la funcion flecha dos';
}
3

Apply implicit return — drop braces and return

Because the body is just one expression, drop the curly braces and the return keyword entirely.
arrow with implicit return
const saludar3 = () => 'Saludos desde la funcion flecha tres';

console.log(saludar3());
// → Saludos desde la funcion flecha tres

this Binding

This is the most important behavioral difference between arrow functions and regular functions. A regular function gets its own this at call time — its value depends on how the function is called (the object before the dot, call, apply, bind, or the global object in sloppy mode). An arrow function captures this lexically — it inherits this from the surrounding scope where the arrow was defined, and it cannot be rebound later with call, apply, or bind.
this binding — regular vs arrow
class Temporizador {
    constructor() {
        this.segundos = 0;
    }

    iniciarRegular() {
        // Regular function: 'this' is undefined in strict mode (or window in sloppy mode)
        setInterval(function() {
            this.segundos++; // ❌ 'this' is NOT the Temporizador instance
            console.log(this.segundos);
        }, 1000);
    }

    iniciarFlecha() {
        // Arrow function: 'this' is captured from iniciarFlecha's scope → the instance
        setInterval(() => {
            this.segundos++; // ✅ 'this' IS the Temporizador instance
            console.log(this.segundos);
        }, 1000);
    }
}

const t = new Temporizador();
t.iniciarFlecha(); // 1, 2, 3, 4 ...
Arrow functions do not have their own arguments object either. If you need to access the raw arguments list inside a variadic function, use a regular function or rest parameters (...args) instead:
rest parameters as the arrow-friendly alternative
// ❌ arguments is not defined in arrow functions
const suma = () => {
    console.log(arguments); // ReferenceError in strict mode
};

// ✅ Use rest parameters instead
const sumaRest = (...args) => {
    return args.reduce((acc, val) => acc + val, 0);
};

console.log(sumaRest(1, 2, 3, 4)); // → 10

Arrow Functions with Array Methods

Arrow functions pair naturally with array higher-order methods because the callbacks are short and this-free.
Use arrow functions with map, filter, and reduce to write expressive, readable data transformations:
array methods with arrow functions
const numeros = [1, 2, 3, 4, 5, 6];

// filter — keep only even numbers
const pares = numeros.filter(n => n % 2 === 0);
console.log(pares); // → [2, 4, 6]

// map — double each value
const dobles = numeros.map(n => n * 2);
console.log(dobles); // → [2, 4, 6, 8, 10, 12]

// reduce — sum everything
const total = numeros.reduce((acc, n) => acc + n, 0);
console.log(total); // → 21

Compared to Classic Function Expressions

funcionFlecha-3.js — classic vs arrow callback
// Classic function expression passed as argument
const funcionParametrosClasica = function(mensaje) {
    console.log(mensaje);
}

funcionParametrosClasica('Saludos desde la funcion clasica');

// Arrow function equivalent — same behaviour, less syntax
const funcionParametros = (mensaje) => console.log(mensaje);

funcionParametros('saludos desde esta funcion con parametros');
Both produce the same output — the arrow version simply removes the function keyword, adds =>, and (for a single-expression body) drops the curly braces entirely.

Build docs developers (and LLMs) love