Introducción a JavaScript
¿Por qué aprender JavaScript?
¡Hola Mundo! en Mac
¡Hola Mundo! en Windows
Anatomía de una variable
Tipos de datos en JavaScript
Creación de strings
Operadores aritméticos
Conversión de tipos: Type Casting y Coerción
Conversión de tipos explícita e implícita
Estructuras de Control y Lógica
Operadores de comparación
Operadores lógicos
Ejecución condicional: if
Ejercicio: Adivina el número
Ejecución condicional: switch
Loop: for
Loop: for of
Loop: for in
Loop: while
Loop: do while
Funciones y This
Anatomía de una función
Funciones vs Métodos
Funciones puras e impuras
Arrow function y enlace léxico
Contextos de ejecución y scope chain
¿Qué es Closure?
Preguntas a Desarrolladores Senior: ¿Por qué aprender Desarrollo Web?
Manipulación de Arrays
Introducción a Arrays
Mutabilidad e inmutabilidad de Arrays
Modificación básica del final con push( ), pop( )
Iteración con map( ) y forEach( )
Filtrado y reducción con filter( ) y reduce( )
Búsqueda de elementos con find( ) y findIndex( )
Crear copias con slice( )
Spread operator: casos de uso
Programación Orientada a Objetos
Anatomía de un Objeto
Trabajando con objetos en JavaScript
Función constructora
¿Qué es una clase?
Prototipos y herencias
Herencia en la práctica
Prototipos en la práctica
this en JavaScript
Proyecto: Crea una red social
Proyecto: Crea una red social parte 2
Asincronía en JavaScript
¿Cómo funciona el JavaScript Engine?
Promesas en JavaScript
Usando Async y await en JavaScript
For await of
¿Cómo funciona la web?
¿Cómo funciona HTTP?
Método GET en JavaScript
Método POST en JavaScript
Método DELETE en JavaScript
Importancia del id en el método DELETE
ECMAScript 6 y tus siguientes pasos
You don't have access to this class
Keep learning! Join and start boosting your career
Arrow Functions have revolutionized the way we write JavaScript code. By replacing traditional functions, they simplify code and avoid context issues. But why are they so important and how exactly are they different from traditional functions? We explore this essential concept of modern development.
Traditional functions in JavaScript, while effective, are often large and unwieldy, especially in the context of this
handling. This is where Arrow Functions come into play. The main benefits are:
=>
, the code becomes more compact.this
: Arrow Functions do not have their own this
context, which is a relief in situations where you need to maintain a fixed context.Let's transform a traditional function to an Arrow Function to illustrate this evolution.
// Traditional Functionconst greeting = function(name) { return `Hello ${name}`;};
// Arrow Functionconst greetingNew = (name) => `Hello ${name}`;
We can see that we have simplified the declaration by removing the word function
and using an arrow.
The simplicity of Arrow Functions allows us to use implicit returns, which means that we do not need to explicitly write return
nor the braces {}
when the whole body of the function is an expression.
// Implicit returnconst greetingImplicit = name => `Hello ${name}`;
This advantage is most obvious with functions that perform simple operations.
When working with multiple parameters, improper use of parentheses can cause errors. In Arrow Functions, parentheses are necessary only when there are multiple parameters.
const greetingComplete = (firstName, lastName) => `Hello, this is ${firstName} ${lastName}`;
By keeping the parentheses, we manage the parameters smoothly.
Arrow Functions facilitate what is known as lexical binding, especially in the handling of this
objects and contexts. Let's see a practical example:
const characterFictitious character = { name: "uncle Ben", messageConTraditionalFunction: function(message) { console.log(`${this.name} says: ${message}`); }, messageConArrowFunction: (message) => { console.log(`${this.name} says: ${message}`); } } };
characterFictitious.messageConTraditionalFunction("With great power comes great responsibility");characterFictitious.messageConArrowFunction("Beware of Dr. Octopus");
In this example, the traditional function correctly accesses the this.name
, while the Arrow Function does not, since Arrow Functions do not bind their own this.
this
in object contexts.Arrow Functions not only simplify code, but also solve common problems associated with this
, allowing you to focus more on logic and less on context handling. Continue to explore and experiment to discover how they can transform your programming style.
Contributions 32
Questions 5
Want to see more contributions, questions and answers from the community?