Skip to content

Commit 33f834a

Browse files
Merge pull request #334 from ezzep66/translate-arrow-functions-basics
Arrow functions, the basics
2 parents 287a5dc + 28b6160 commit 33f834a

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

1-js/02-first-steps/17-arrow-functions-basics/1-rewrite-arrow/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ ask(
1414
);
1515
```
1616

17-
Looks short and clean, right?
17+
Se ve corto y limpio, ¿verdad?

1-js/02-first-steps/17-arrow-functions-basics/1-rewrite-arrow/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
# Rewrite with arrow functions
2+
# Reescribe con funciones de flecha
33

4-
Replace Function Expressions with arrow functions in the code below:
4+
Reemplace las expresiones de función con funciones de flecha en el código a continuación:
55

66
```js run
77
function ask(question, yes, no) {
Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
# Arrow functions, the basics
1+
# Funciones Flecha, lo básico
22

3-
There's another very simple and concise syntax for creating functions, that's often better than Function Expressions.
3+
Hay otra sintaxis muy simple y concisa para crear funciones, que a menudo es mejor que las Expresiones de funciones.
44

5-
It's called "arrow functions", because it looks like this:
5+
Se llama "funciones de flecha", porque se ve así:
66

77
```js
88
let func = (arg1, arg2, ...argN) => expression
99
```
1010

11-
...This creates a function `func` that accepts arguments `arg1..argN`, then evaluates the `expression` on the right side with their use and returns its result.
11+
...Esto crea una función `func` que acepta parámetros `arg1..argN`, luego evalúa la `expression` de la derecha con su uso y devuelve su resultado.
1212

13-
In other words, it's the shorter version of:
13+
En otras palabras, es la versión más corta de:
1414

1515
```js
1616
let func = function(arg1, arg2, ...argN) {
1717
return expression;
1818
};
1919
```
2020

21-
Let's see a concrete example:
21+
Veamos un ejemplo concreto:
2222

2323
```js run
2424
let sum = (a, b) => a + b;
2525

26-
/* This arrow function is a shorter form of:
26+
/* Esta función de flecha es una forma más corta de:
2727
2828
let sum = function(a, b) {
2929
return a + b;
@@ -33,32 +33,32 @@ let sum = function(a, b) {
3333
alert( sum(1, 2) ); // 3
3434
```
3535

36-
As you can, see `(a, b) => a + b` means a function that accepts two arguments named `a` and `b`. Upon the execution, it evaluates the expression `a + b` and returns the result.
36+
Como puedes ver `(a, b) => a + b` significa una función que acepta dos parámetros llamados `a` y `b`. Tras la ejecución, evalúa la expresión `a + b` y devuelve el resultado.
3737

38-
- If we have only one argument, then parentheses around parameters can be omitted, making that even shorter.
38+
- Si solo tenemos un argumento, se pueden omitir paréntesis alrededor de los parámetros, lo que lo hace aún más corto.
3939

40-
For example:
40+
Por ejemplo:
4141

4242
```js run
4343
*!*
4444
let double = n => n * 2;
45-
// roughly the same as: let double = function(n) { return n * 2 }
45+
// Más o menos lo mismo que: let double = function(n) { return n * 2 }
4646
*/!*
4747

4848
alert( double(3) ); // 6
4949
```
5050

51-
- If there are no arguments, parentheses will be empty (but they should be present):
51+
- Si no hay parámetros, los paréntesis estarán vacíos (pero deberían estar presentes):
5252

5353
```js run
5454
let sayHi = () => alert("Hello!");
5555
5656
sayHi();
5757
```
5858

59-
Arrow functions can be used in the same way as Function Expressions.
59+
Las funciones de flecha se pueden usar de la misma manera que las expresiones de función.
6060

61-
For instance, to dynamically create a function:
61+
Por ejemplo, para crear dinámicamente una función:
6262

6363
```js run
6464
let age = prompt("What is your age?", 18);
@@ -70,42 +70,42 @@ let welcome = (age < 18) ?
7070
welcome();
7171
```
7272

73-
Arrow functions may appear unfamiliar and not very readable at first, but that quickly changes as the eyes get used to the structure.
73+
Las funciones de flecha pueden parecer desconocidas y poco legibles al principio, pero eso cambia rápidamente a medida que los ojos se acostumbran a la estructura.
7474

75-
They are very convenient for simple one-line actions, when we're just too lazy to write many words.
75+
Son muy convenientes para acciones simples de una línea, cuando somos demasiado flojos para escribir muchas palabras.
7676

77-
## Multiline arrow functions
77+
## Funciones de flecha multilínea
7878

79-
The examples above took arguments from the left of `=>` and evaluated the right-side expression with them.
79+
Los ejemplos anteriores tomaron parámetros de la izquierda de `=>` y evaluaron el lado derecho de la expressión con ellos.
8080

81-
Sometimes we need something a little bit more complex, like multiple expressions or statements. It is also possible, but we should enclose them in curly braces. Then use a normal `return` within them.
81+
A veces necesitamos algo un poco más complejo, como múltiples expresiones o declaraciones. También es posible, pero debemos encerrarlos entre llaves. Luego usa un `return` normal dentro de ellas.
8282

83-
Like this:
83+
Como esto:
8484

8585
```js run
86-
let sum = (a, b) => { // the curly brace opens a multiline function
86+
let sum = (a, b) => { // la llave abre una función multilínea
8787
let result = a + b;
8888
*!*
89-
return result; // if we use curly braces, then we need an explicit "return"
89+
return result; // si usamos llaves, entonces necesitamos un "return" explícito
9090
*/!*
9191
};
9292
9393
alert( sum(1, 2) ); // 3
9494
```
9595

96-
```smart header="More to come"
97-
Here we praised arrow functions for brevity. But that's not all!
96+
```smart header="Más por venir"
97+
Aquí elogiamos las funciones de flecha por su brevedad. ¡Pero eso no es todo!
9898
99-
Arrow functions have other interesting features.
99+
Las funciones de flecha tienen otras características interesantes.
100100
101-
To study them in-depth, we first need to get to know some other aspects of JavaScript, so we'll return to arrow functions later in the chapter <info:arrow-functions>.
101+
Para estudiarlas en profundidad, primero debemos conocer algunos otros aspectos de JavaScript, por lo que volveremos a las funciones de flecha más adelante en el capítulo <info:arrow-functions>.
102102
103-
For now, we can already use arrow functions for one-line actions and callbacks.
103+
Por ahora, ya podemos usar las funciones de flecha para acciones de una línea y devoluciones de llamada.
104104
```
105105

106-
## Summary
106+
## Resumen
107107

108-
Arrow functions are handy for one-liners. They come in two flavors:
108+
Las funciones de flecha son útiles para líneas simples. Vienen en dos variantes:
109109

110-
1. Without curly braces: `(...args) => expression` -- the right side is an expression: the function evaluates it and returns the result.
111-
2. With curly braces: `(...args) => { body }` -- brackets allow us to write multiple statements inside the function, but we need an explicit `return` to return something.
110+
1. Sin llaves: `(...args) => expression` -- el lado derecho es una expresión: la función lo evalúa y devuelve el resultado.
111+
2. Con llaves: `(...args) => { body }` -- los paréntesis nos permiten escribir varias declaraciones dentro de la función, pero necesitamos un `return` explícito para devolver algo.

0 commit comments

Comments
 (0)