Skip to content

Commit 0f2536d

Browse files
authored
Merge pull request #305 from joaquinelio/bigint
BigInt
2 parents 80c8685 + 45e7b19 commit 0f2536d

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

1-js/99-js-misc/05-bigint/article.md

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,129 +2,129 @@
22

33
[recent caniuse="bigint"]
44

5-
`BigInt` is a special numeric type that provides support for integers of arbitrary length.
5+
`BigInt` es un tipo numérico especial que provee soporte a enteros de tamaño arbitrario.
66

7-
A bigint is created by appending `n` to the end of an integer literal or by calling the function `BigInt` that creates bigints from strings, numbers etc.
7+
Un bigint se crea agregando `n` al final del literal entero o llamando a la función `BigInt` que crea bigints desde cadenas, números, etc.
88

99
```js
1010
const bigint = 1234567890123456789012345678901234567890n;
1111

1212
const sameBigint = BigInt("1234567890123456789012345678901234567890");
1313

14-
const bigintFromNumber = BigInt(10); // same as 10n
14+
const bigintFromNumber = BigInt(10); // lo mismo que 10n
1515
```
1616

17-
## Math operators
17+
## Operadores matemáticos
1818

19-
`BigInt` can mostly be used like a regular number, for example:
19+
`BigInt` puede ser usado mayormente como un número regular, por ejemplo:
2020

2121
```js run
2222
alert(1n + 2n); // 3
2323

2424
alert(5n / 2n); // 2
2525
```
2626

27-
Please note: the division `5/2` returns the result rounded towards zero, without the decimal part. All operations on bigints return bigints.
27+
Por favor, ten en cuenta: la división `5/2` devuelve el resultado redondeado a cero, sin la parte decimal. Todas las operaciones sobre bigints devuelven bigints.
2828

29-
We can't mix bigints and regular numbers:
29+
No podemos mezclar bigints con números regulares:
3030

3131
```js run
32-
alert(1n + 2); // Error: Cannot mix BigInt and other types
32+
alert(1n + 2); // Error: No se puede mezclar BigInt y otros tipos.
3333
```
3434

35-
We should explicitly convert them if needed: using either `BigInt()` or `Number()`, like this:
35+
Podemos convertirlos explícitamente cuando es necesario: usando `BigInt()` o `Number()` como aquí:
3636

3737
```js run
3838
let bigint = 1n;
3939
let number = 2;
4040

41-
// number to bigint
41+
// De number a bigint
4242
alert(bigint + BigInt(number)); // 3
4343

44-
// bigint to number
44+
// De bigint a number
4545
alert(Number(bigint) + number); // 3
4646
```
4747

48-
The conversion operations are always silent, never give errors, but if the bigint is too huge and won't fit the number type, then extra bits will be cut off, so we should be careful doing such conversion.
48+
Las operaciones de conversión siempre son silenciosas, nunca dan error, pero si el bigint es tan gigante que no podrá ajustarse al tipo numérico, los bits extra serán recortados, entonces deberíamos ser cuidadosos al hacer tal conversión.
4949

50-
````smart header="The unary plus is not supported on bigints"
51-
The unary plus operator `+value` is a well-known way to convert `value` to a number.
50+
````smart header="El unario más no tiene soporte en bigints"
51+
El operador unario más `+value` es una manera bien conocida de convertir `value` a number.
5252
53-
On bigints it's not supported, to avoid confusion:
53+
Para evitar las confusiones, con bigints eso no es soportado:
5454
```js run
5555
let bigint = 1n;
5656
5757
alert( +bigint ); // error
5858
```
59-
So we should use `Number()` to convert a bigint to a number.
59+
Entonces debemos usar `Number()` para convertir un bigint a number.
6060
````
6161

62-
## Comparisons
62+
## Comparaciones
6363

64-
Comparisons, such as `<`, `>` work with bigints and numbers just fine:
64+
Comparaciones tales como `<`, `>` funcionan bien entre bigints y numbers:
6565

6666
```js run
6767
alert( 2n > 1n ); // true
6868

6969
alert( 2n > 1 ); // true
7070
```
7171

72-
Please note though, as numbers and bigints belong to different types, they can be equal `==`, but not strictly equal `===`:
72+
Por favor, nota que como number y bigint pertenecen a diferentes tipos, ellos pueden ser iguales `==`, pero no estrictamente iguales `===`:
7373

7474
```js run
7575
alert( 1 == 1n ); // true
7676

7777
alert( 1 === 1n ); // false
7878
```
7979

80-
## Boolean operations
80+
## Operaciones booleanas
8181

82-
When inside `if` or other boolean operations, bigints behave like numbers.
82+
Cuando estan dentro de un `if` u otra operación booleana, los bigints se comportan como numbers.
8383

84-
For instance, in `if`, bigint `0n` is falsy, other values are truthy:
84+
Por ejemplo, en `if`, el bigint `0n` es falso, los otros valores son verdaderos:
8585

8686
```js run
8787
if (0n) {
88-
// never executes
88+
// nunca se ejecuta
8989
}
9090
```
9191

92-
Boolean operators, such as `||`, `&&` and others also work with bigints similar to numbers:
92+
Los operadores booleanos, tales como `||`, `&&` y otros, también trabajan con bigints en forma similar a los number:
9393

9494
```js run
95-
alert( 1n || 2 ); // 1 (1n is considered truthy)
95+
alert( 1n || 2 ); // 1 (1n es considerado verdadero)
9696

97-
alert( 0n || 2 ); // 2 (0n is considered falsy)
97+
alert( 0n || 2 ); // 2 (0n es considerado falso)
9898
```
9999

100100
## Polyfills
101101

102-
Polyfilling bigints is tricky. The reason is that many JavaScript operators, such as `+`, `-` and so on behave differently with bigints compared to regular numbers.
102+
Hacer Polyfill con bigints es trabajoso. La razón es que muchos operadores JavaScript como `+`, `-` y otros se comportan de diferente manera comparados con los números regulares.
103103

104-
For example, division of bigints always returns a bigint (rounded if necessary).
104+
Por ejemplo, la división de bigints siempre devuelve un bigint (redondeado cuando es necesario).
105105

106-
To emulate such behavior, a polyfill would need to analyze the code and replace all such operators with its functions. But doing so is cumbersome and would cost a lot of performance.
106+
Para emular tal comportamiento, un polyfill necesitaría analizar el código y reemplazar todos los operadores con sus funciones. Pero hacerlo es engorroso y tendría mucho costo en performance.
107107

108-
So, there's no well-known good polyfill.
108+
Por lo que no se conoce un buen polyfill.
109109

110-
Although, the other way around is proposed by the developers of [JSBI](https://github.com/GoogleChromeLabs/jsbi) library.
110+
Aunque hay otra manera, la propuesta por los desarrolladores de la librería [JSBI](https://github.com/GoogleChromeLabs/jsbi).
111111

112-
This library implements big numbers using its own methods. We can use them instead of native bigints:
112+
Esta librería implementa bigint usando sus propios métodos. Podemos usarlos en lugar de bigints nativos:
113113

114-
| Operation | native `BigInt` | JSBI |
114+
| Operación | `BigInt` nativo | JSBI |
115115
|-----------|-----------------|------|
116-
| Creation from Number | `a = BigInt(789)` | `a = JSBI.BigInt(789)` |
117-
| Addition | `c = a + b` | `c = JSBI.add(a, b)` |
118-
| Subtraction | `c = a - b` | `c = JSBI.subtract(a, b)` |
116+
| Creación desde Number | `a = BigInt(789)` | `a = JSBI.BigInt(789)` |
117+
| Suma | `c = a + b` | `c = JSBI.add(a, b)` |
118+
| Resta | `c = a - b` | `c = JSBI.subtract(a, b)` |
119119
| ... | ... | ... |
120120

121-
...And then use the polyfill (Babel plugin) to convert JSBI calls to native bigints for those browsers that support them.
121+
...Y entonces usar polyfill (plugin Babel) para convertir las llamadas de JSBI en bigints nativos para aquellos navegadores que los soporten.
122122

123-
In other words, this approach suggests that we write code in JSBI instead of native bigints. But JSBI works with numbers as with bigints internally, emulates them closely following the specification, so the code will be "bigint-ready".
123+
En otras palabras, este enfoque sugiere que escribamos código en JSBI en lugar de bigints nativos. Pero JSBI trabaja internamente tanto con numbers como con bigints, los emula siguiendo de cerca la especificación, entonces el código será "bigint-ready" (preparado para bigint).
124124

125-
We can use such JSBI code "as is" for engines that don't support bigints and for those that do support - the polyfill will convert the calls to native bigints.
125+
Podemos usar tal código JSBI "tal como está" en motores que no soportan bigints, y para aquellos que sí lo soportan - el polyfill convertirá las llamadas en bigints nativos.
126126

127-
## References
127+
## Referencias
128128

129-
- [MDN docs on BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt).
130-
- [Specification](https://tc39.es/ecma262/#sec-bigint-objects).
129+
- [MDN documentación BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt).
130+
- [Especificación](https://tc39.es/ecma262/#sec-bigint-objects).

0 commit comments

Comments
 (0)