Explica este código JavaScript
const num = parseInt("7*6", 10);
console.log(num); //?
- A:
42
- B:
"42"
- C:
7
- D:
NaN
Respuesta en el primer comentario.
For further actions, you may consider blocking this person and/or reporting abuse
Khushal Bhardwaj -
Rashid Shamloo -
Jenuel Oras Ganawed -
Jenuel Oras Ganawed -
Once suspended, duxtech will not be able to comment or publish posts until their suspension is removed.
Once unsuspended, duxtech will be able to comment and publish posts again.
Once unpublished, all posts by duxtech will become hidden and only accessible to themselves.
If duxtech is not suspended, they can still re-publish their posts from their dashboard.
Once unpublished, this post will become invisible to the public and only accessible to Cristian Fernando .
They can still re-publish the post if they are not suspended.
Thanks for keeping DEV Community safe. Here is what you can do to flag duxtech:
Unflagging duxtech will restore default visibility to their posts.
Top comments (1)
Respuesta:
7
parseInt
convierte un valor a tiponumber
de una base concreta (base binaria, octal, decimal, etc).En el ejemplo intentamos convertir
"7*6"
a base10
, osea, a base decimal.parseInt
toma los valores validos de izquierda a derecha, dicho esto, solo tomará el valor7
(el*
y todo lo que le precede no es un valor valido paraparseInt
).En conclusión, solo convierte al
7
destring
anumber
.