Skip to content

Commit edba311

Browse files
authored
Merge pull request #44 from SantiEspada/master
The modern mode, "use strict"
2 parents 5b4d97a + 0ba9c2b commit edba311

File tree

1 file changed

+34
-35
lines changed

1 file changed

+34
-35
lines changed
Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,78 @@
1-
# The modern mode, "use strict"
1+
# El modo moderno, "use strict"
22

3-
For a long time, JavaScript evolved without compatibility issues. New features were added to the language while old functionality didn't change.
3+
Durante mucho tiempo, JavaScript evolucionó sin problemas de compatibilidad. Se añadían nuevas características al lenguaje sin que la funcionalidad existente cambiase.
44

5-
That had the benefit of never breaking existing code. But the downside was that any mistake or an imperfect decision made by JavaScript's creators got stuck in the language forever.
5+
Esto tenía el beneficio de nunca romper código existente, pero lo malo era que cualquier error o decisión imperfecta tomada por los creadores de JavaScript se quedaba para siempre en el lenguage.
66

7-
This was the case until 2009 when ECMAScript 5 (ES5) appeared. It added new features to the language and modified some of the existing ones. To keep the old code working, most modifications are off by default. You need to explicitly enable them with a special directive: `"use strict"`.
7+
Esto fue así hasta 2009, cuando ECMAScript 5 (ES5) apareció. Esta versión añadío nuevas características al lenguaje y modificó algunas de las ya existentes. Para mantener el código antiguo funcionando, la mayor parte de las modificaciones están desactivadas por defecto. Tienes que activarlas explícitamente usando una directiva especial: `"use strict"`.
88

99
## "use strict"
1010

11-
The directive looks like a string: `"use strict"` or `'use strict'`. When it is located at the top of a script, the whole script works the "modern" way.
11+
La directiva se asemeja a un string: `"use strict"`. Cuando se sitúa al principio de un script, el script entero funciona de la manera "moderna".
1212

13-
For example:
13+
Por ejemplo:
1414

1515
```js
1616
"use strict";
1717

18-
// this code works the modern way
18+
// este código funciona de la manera moderna
1919
...
2020
```
2121

22-
We will learn functions (a way to group commands) soon.
22+
Aprenderemos funciones (una manera de agrupar comandos) en breve.
2323

24-
Looking ahead, let's just note that `"use strict"` can be put at the start of most kinds of functions instead of the whole script. Doing that enables strict mode in that function only. But usually, people use it for the whole script.
24+
De cara al futuro, tengamos en cuenta que `"use strict"` se puede poner al inicio de la mayoría de los tipos de funciones en lugar del script entero. De esta manera, se activa el modo estricto únicamente en esa función. Pero, normalmente, la gente lo utiliza para el script entero.
2525

26+
````warn header="Asegúrate de que \"use strict\" está al inicio"
27+
Por favor, asegúrate de que `"use strict"` está al principio de tus scripts. Si no, el modo estricto podría no estar activado.
2628
27-
````warn header="Ensure that \"use strict\" is at the top"
28-
Please make sure that `"use strict"` is at the top of your scripts, otherwise strict mode may not be enabled.
29-
30-
Strict mode isn't enabled here:
29+
El modo estricto no está activado aquí:
3130
3231
```js no-strict
33-
alert("some code");
34-
// "use strict" below is ignored--it must be at the top
32+
alert("algo de código");
33+
// la directiva "use strict" de abajo es ignorada, tiene que estar al principio
3534
3635
"use strict";
3736
38-
// strict mode is not activated
37+
// el modo estricto no está activado
3938
```
4039
41-
Only comments may appear above `"use strict"`.
40+
Únicamente pueden aparecer comentarios por encima de `"use strict"`.
4241
````
4342

44-
```warn header="There's no way to cancel `use strict`"
45-
There is no directive like `"no use strict"` that reverts the engine to old behavior.
43+
````warn header="No hay manera de cancelar `use strict`"
44+
No hay ninguna directiva del tipo `"no use strict"` que haga al motor volver al comportamiento anterior.
4645

47-
Once we enter strict mode, there's no return.
48-
```
46+
Una vez entramos en modo estricto, no hay vuelta atrás.
47+
````
4948
50-
## Browser console
49+
## Consola del navegador
5150
52-
For the future, when you use a browser console to test features, please note that it doesn't `use strict` by default.
51+
A partir de ahora, cuando utilices la consola del navegador para probar características, ten en cuenta que no utiliza `use strict` por defecto.
5352
54-
Sometimes, when `use strict` makes a difference, you'll get incorrect results.
53+
En ocasiones, cuando `use strict` causa una diferencia, obtendrás resultados incorrectos.
5554
56-
Even if we press `key:Shift+Enter` to input multiple lines, and put `use strict` on top, it doesn't work. That's because of how the console executes the code internally.
55+
Incluso si pulsamos `key:Shift+Enter` para ingresar múltiples líneas y ponemos `use strict` al principio, no funciona. Esto es por cómo la consola ejecuta el código internamente.
5756
58-
The reliable way to ensure `use strict` would be to input the code into console like this:
57+
La única manera confiable de asegurar que `use strict` funcionará sería escribir el código en la consola de la siguiente forma:
5958
6059
```js
6160
(function() {
6261
'use strict';
6362
64-
// ...your code...
63+
// ...tu código...
6564
})()
6665
```
6766
68-
## Always "use strict"
67+
## Utiliza siempre "use strict"
6968
70-
We have yet to cover the differences between strict mode and the "default" mode.
69+
Aún tenemos que comentar las diferencias entre el modo estricto y el modo "por defecto".
7170
72-
In the next chapters, as we learn language features, we'll note the differences between the strict and default modes. Luckily, there aren't many and they actually make our lives better.
71+
En los siguientes capítulos, según aprendamos características del lenguaje, veremos las diferencias entre los modos estricto y por defecto. Afortunadamente, no hay tantas y, de hecho, nos hacen la vida más fácil.
7372
74-
For now, it's enough to know about it in general:
73+
De momento, es suficiente saber lo general:
7574
76-
1. The `"use strict"` directive switches the engine to the "modern" mode, changing the behavior of some built-in features. We'll see the details later in the tutorial.
77-
2. Strict mode is enabled by placing `"use strict"` at the top of a script or function. Several language features, like "classes" and "modules", enable strict mode automatically.
78-
3. Strict mode is supported by all modern browsers.
79-
4. We recommended always starting scripts with `"use strict"`. All examples in this tutorial assume strict mode unless (very rarely) specified otherwise.
75+
1. La directiva `"use strict"` cambia el motor de ejecución al modo "moderno", modificando el comportamiento de algunas características incluídas en el lenguaje. Veremos los detalles más adelante.
76+
2. El modo estricto se habilita poniendo `"use strict"` al principio de una función o del script. Varias características del lenguaje, como las "clases" y los "módulos", activan el modo estricto automáticamente.
77+
3. El modo estricto funciona en todos los navegadores modernos.
78+
4. Recomendamos empezar todos los scripts siempre con `"use strict"`. Todos los ejemplos de este tutorial asumen que el modo estricto está activado excepto cuando (muy raramente) se especifica lo contrario.

0 commit comments

Comments
 (0)