Skip to content

Commit 0189e27

Browse files
author
Maksumi Murakami
authored
Merge pull request #1 from javascript-tutorial/master
Actualizado
2 parents bd8ad7a + 80c8685 commit 0189e27

File tree

30 files changed

+581
-580
lines changed

30 files changed

+581
-580
lines changed

1-js/02-first-steps/14-switch/2-rewrite-if-switch/solution.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The first two checks turn into two `case`. The third check is split into two cases:
1+
Las primeras dos validaciones se vuelven dos`case`. La tercera validación se separa en dos casos:
22

33
```js run
44
let a = +prompt('a?', '');
@@ -21,6 +21,6 @@ switch (a) {
2121
}
2222
```
2323

24-
Please note: the `break` at the bottom is not required. But we put it to make the code future-proof.
24+
Nota: El `break` al final no es requerido. Pero lo agregamos para preparar el código para el futuro.
2525

26-
In the future, there is a chance that we'd want to add one more `case`, for example `case 4`. And if we forget to add a break before it, at the end of `case 3`, there will be an error. So that's a kind of self-insurance.
26+
En el futuro existe una probabilidad de que querramos agregar un `case` adicional, por ejemplo `case 4`. Y si olvidamos agregar un break antes, al final de `case 3`, habrá un error. Por tanto, es una forma de auto-asegurarse.
Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
# The "switch" statement
1+
# La sentencia "switch"
22

3-
A `switch` statement can replace multiple `if` checks.
3+
Una sentencia `switch` puede reemplazar múltiples condiciones `if`.
44

5-
It gives a more descriptive way to compare a value with multiple variants.
5+
Provee una mejor manera de comparar un valor con sus múltiples variantes.
66

7-
## The syntax
7+
## La sintaxis
88

9-
The `switch` has one or more `case` blocks and an optional default.
9+
`switch` tiene uno o mas bloques `case`y un opcional `default`.
1010

11-
It looks like this:
11+
Se ve de esta forma:
1212

1313
```js no-beautify
1414
switch(x) {
15-
case 'value1': // if (x === 'value1')
15+
case 'valor1': // if (x === 'valor1')
1616
...
1717
[break]
1818

19-
case 'value2': // if (x === 'value2')
19+
case 'valor2': // if (x === 'valor2')
2020
...
2121
[break]
2222

@@ -26,71 +26,71 @@ switch(x) {
2626
}
2727
```
2828

29-
- The value of `x` is checked for a strict equality to the value from the first `case` (that is, `value1`) then to the second (`value2`) and so on.
30-
- If the equality is found, `switch` starts to execute the code starting from the corresponding `case`, until the nearest `break` (or until the end of `switch`).
31-
- If no case is matched then the `default` code is executed (if it exists).
29+
- El valor de `x` es comparado contra el valor del primer `case` (en este caso, `valor1`), luego contra el segundo (`valor2`) y así sucesivamente, todo esto bajo una igualdad estricta.
30+
- Si la igualdad es encontrada, `switch` empieza a ejecutar el código iniciando por el primer `case` correspondiente, hasta el `break` más cercano (o hasta el final del `switch`).
31+
- Si no se cumple ningún caso entonces el código `default` es ejecutado (si existe).
3232

33-
## An example
33+
## Ejemplo
3434

35-
An example of `switch` (the executed code is highlighted):
35+
Un ejemplo de `switch` (se resalta el código ejecutado):
3636

3737
```js run
3838
let a = 2 + 2;
3939

4040
switch (a) {
4141
case 3:
42-
alert( 'Too small' );
42+
alert( 'Muy pequeño' );
4343
break;
4444
*!*
4545
case 4:
46-
alert( 'Exactly!' );
46+
alert( '¡Exacto!' );
4747
break;
4848
*/!*
4949
case 5:
50-
alert( 'Too large' );
50+
alert( 'Muy grande' );
5151
break;
5252
default:
53-
alert( "I don't know such values" );
53+
alert( "Desconozco estos valores" );
5454
}
5555
```
5656

57-
Here the `switch` starts to compare `a` from the first `case` variant that is `3`. The match fails.
57+
Aquí el `switch` inicia comparando `a` con la primera variante `case` que es `3`. La comparación falla.
5858

59-
Then `4`. That's a match, so the execution starts from `case 4` until the nearest `break`.
59+
Luego `4`. La comparación es exitosa, por tanto la ejecución empieza desde `case 4` hasta el `break` más cercano.
6060

61-
**If there is no `break` then the execution continues with the next `case` without any checks.**
61+
**Si no existe `break` entonces la ejecución continúa con el próximo `case` sin ninguna revisión.**
6262

63-
An example without `break`:
63+
Un ejemplo sin `break`:
6464

6565
```js run
6666
let a = 2 + 2;
6767

6868
switch (a) {
6969
case 3:
70-
alert( 'Too small' );
70+
alert( 'Muy pequeño' );
7171
*!*
7272
case 4:
73-
alert( 'Exactly!' );
73+
alert( '¡Exacto!' );
7474
case 5:
75-
alert( 'Too big' );
75+
alert( 'Muy grande' );
7676
default:
77-
alert( "I don't know such values" );
77+
alert( "Desconozco estos valores" );
7878
*/!*
7979
}
8080
```
8181

82-
In the example above we'll see sequential execution of three `alert`s:
82+
En el ejemplo anterior veremos ejecuciones de tres `alert` secuenciales:
8383

8484
```js
85-
alert( 'Exactly!' );
86-
alert( 'Too big' );
87-
alert( "I don't know such values" );
85+
alert( '¡Exacto!' );
86+
alert( 'Muy grande' );
87+
alert( "Desconozco estos valores" );
8888
```
8989

90-
````smart header="Any expression can be a `switch/case` argument"
91-
Both `switch` and `case` allow arbitrary expressions.
90+
````encabezado inteligente="Cualquier expresión puede ser un argumento `switch/case`"
91+
Ambos `switch` y `case` permiten expresiones arbitrarias.
9292

93-
For example:
93+
Por ejemplo:
9494

9595
```js run
9696
let a = "1";
@@ -99,74 +99,75 @@ let b = 0;
9999
switch (+a) {
100100
*!*
101101
case b + 1:
102-
alert("this runs, because +a is 1, exactly equals b+1");
102+
alert("esto se ejecuta, porque +a es 1, exactamente igual b+1");
103103
break;
104104
*/!*
105105

106106
default:
107-
alert("this doesn't run");
107+
alert("esto no se ejecuta");
108108
}
109109
```
110-
Here `+a` gives `1`, that's compared with `b + 1` in `case`, and the corresponding code is executed.
110+
Aquí `+a` da `1`, esto es comparado con `b + 1` en `case`, y el código correspondiente es ejecutado.
111111
````
112112
113-
## Grouping of "case"
113+
## Agrupamiento de "case"
114114
115-
Several variants of `case` which share the same code can be grouped.
115+
Varias variantes de `case` los cuales comparten el mismo código pueden ser agrupadas.
116116
117-
For example, if we want the same code to run for `case 3` and `case 5`:
117+
Por ejemplo, si queremos que se ejecute el mismo código para `case 3` y `case 5`:
118118
119119
```js run no-beautify
120120
let a = 2 + 2;
121121
122122
switch (a) {
123123
case 4:
124-
alert('Right!');
124+
alert('¡Correcto!');
125125
break;
126126
127127
*!*
128-
case 3: // (*) grouped two cases
128+
case 3: // (*) agrupando dos cases
129129
case 5:
130-
alert('Wrong!');
131-
alert("Why don't you take a math class?");
130+
alert('¡Incorrecto!');
131+
alert("¿Por qué no tomas una clase de matemáticas?");
132132
break;
133133
*/!*
134134
135135
default:
136-
alert('The result is strange. Really.');
136+
alert('El resultado es extraño. Realmente.');
137137
}
138138
```
139139
140-
Now both `3` and `5` show the same message.
140+
Ahora ambos `3` y `5` muestran el mismo mensaje.
141141
142-
The ability to "group" cases is a side-effect of how `switch/case` works without `break`. Here the execution of `case 3` starts from the line `(*)` and goes through `case 5`, because there's no `break`.
142+
La habilidad para "agrupar" cases es un efecto secundario de como trabaja `switch/case` sin `break`. Aquí la ejecución de `case 3` inicia desde la línea `(*)` y continúa a través de `case 5`, porque no existe `break`.
143143
144-
## Type matters
144+
## El tipo importa
145145
146-
Let's emphasize that the equality check is always strict. The values must be of the same type to match.
146+
Vamos a enfatizar que la comparación de igualdad es siempre estricta. Los valores deben ser del mismo tipo para coincidir.
147147
148-
For example, let's consider the code:
148+
Por ejemplo, consideremos el código:
149149
150150
```js run
151-
let arg = prompt("Enter a value?");
151+
let arg = prompt("Ingrese un valor");
152152
switch (arg) {
153153
case '0':
154154
case '1':
155-
alert( 'One or zero' );
155+
alert( 'Uno o cero' );
156156
break;
157157
158158
case '2':
159-
alert( 'Two' );
159+
alert( 'Dos' );
160160
break;
161161
162162
case 3:
163-
alert( 'Never executes!' );
163+
alert( '¡Nunca ejecuta!' );
164164
break;
165165
default:
166-
alert( 'An unknown value' );
166+
alert( 'Un valor desconocido' );
167167
}
168168
```
169169
170-
1. For `0`, `1`, the first `alert` runs.
171-
2. For `2` the second `alert` runs.
172-
3. But for `3`, the result of the `prompt` is a string `"3"`, which is not strictly equal `===` to the number `3`. So we've got a dead code in `case 3`! The `default` variant will execute.
170+
1. Para `0`, `1`, se ejecuta el primer `alert`.
171+
2. Para `2` se ejecuta el segundo `alert`.
172+
3. Pero para `3`, el resultado del `prompt` es un string `"3"`, el cual no es estrictamente igual `===` al número `3`. Por tanto ¡Tenemos un código muerto en `case 3`! La variante `default` se ejecutará.
173+

1-js/05-data-types/12-json/1-serialize-object/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 5
22

33
---
44

5-
# Turn the object into JSON and back
5+
# Convierte el objeto en JSON y de vuelta
66

7-
Turn the `user` into JSON and then read it back into another variable.
7+
Convierte el `user` a JSON y luego léalo de vuelta en otra variable.
88

99
```js
1010
let user = {

1-js/05-data-types/12-json/2-serialize-event-circular/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ alert( JSON.stringify(meetup, function replacer(key, value) {
2626
*/
2727
```
2828

29-
Here we also need to test `key==""` to exclude the first call where it is normal that `value` is `meetup`.
29+
Aquí también necesitamos verificar `propiedad==""` para excluir el primer llamado donde es normal que `valor` sea `meetup`.
3030

1-js/05-data-types/12-json/2-serialize-event-circular/task.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ importance: 5
22

33
---
44

5-
# Exclude backreferences
5+
# Excluir referencias circulares
66

7-
In simple cases of circular references, we can exclude an offending property from serialization by its name.
7+
En casos simples de referencias circulares, podemos excluir una propiedad infractora de la serialización por su nombre.
88

9-
But sometimes we can't just use the name, as it may be used both in circular references and normal properties. So we can check the property by its value.
9+
Pero a veces no podemos usar el nombre, ya que puede usarse tanto en referencias circulares como en propiedades normales. Entonces podemos verificar la propiedad por su valor.
1010

11-
Write `replacer` function to stringify everything, but remove properties that reference `meetup`:
11+
Escriba la función `replacer` para convertir a string todo, pero elimine las propiedades que hacen referencia a `meetup`:
1212

1313
```js run
1414
let room = {
@@ -22,16 +22,16 @@ let meetup = {
2222
};
2323

2424
*!*
25-
// circular references
25+
// referencias circulares
2626
room.occupiedBy = meetup;
2727
meetup.self = meetup;
2828
*/!*
2929

3030
alert( JSON.stringify(meetup, function replacer(key, value) {
31-
/* your code */
31+
/* tu código */
3232
}));
3333

34-
/* result should be:
34+
/* el resultado debería ser:
3535
{
3636
"title":"Conference",
3737
"occupiedBy":[{"name":"John"},{"name":"Alice"}],

0 commit comments

Comments
 (0)