Skip to content

Instantly share code, notes, and snippets.

@teffcode
Created May 6, 2020 14:12
Show Gist options
  • Save teffcode/348bc3fe39a277db28c97f5d08ff0d0c to your computer and use it in GitHub Desktop.
Save teffcode/348bc3fe39a277db28c97f5d08ff0d0c to your computer and use it in GitHub Desktop.

馃憢馃徏 Welcome 馃憢馃徏

Quiz banner

Instagram | Twitter | LinkedIn


馃憛 Choose your language



馃殌 English version


What does the following code return ?



馃憖 Click here to see the correct answer and explanation
Correct Answer Explanation
A The + operator is available in JavaScript and can be used to add numeric values. In the first console.log, true equals 1 and for this reason the result is 1 + 0 = 1. An interesting thing to note in JavaScript is the result of adding a number (or a Boolean) and a string. Whenever there is a string, JavaScript converts the entire declaration to a string and concatenates it, for this reason the result in the second console.log is true馃崯. You can easily realize this with the following considerations: Number + Number = Sum, Boolean + Number = Sum, Boolean + Boolean = Sum, Number + String = Concatena, String + Boolean = Concatena or String + String = Concatenates.

Explanation based on 馃憠馃徏 Arithmetic operators | MDN Documantation and How To Do Math in JavaScript with Operators | Digital Ocean Blog



馃殌 Spanish version


驴 Qu茅 devuelve el siguiente c贸digo ?



馃憖 Haz click aqu铆 para ver la respuesta correcta y su explicaci贸n
Respuesta correcta Explicaci贸n
A El operador + est谩 disponible en JavaScript y puede usarse para sumar valores num茅ricos. En el primer console.log, true es igual a 1 y por esta raz贸n el resultado es 1 + 0 = 1. Una cosa interesante a tener en cuenta en JavaScript es el resultado de agregar un n煤mero (o un booleano) y una cadena. Cada que hay una cadena, JavaScript convierte la declaraci贸n completa en una cadena y la concatena, por esta raz贸n, el resultado en el segundo console.log es true馃崯. Puedes darte cuenta f谩cilmente de esto con las siguientes consideraciones: Number + Number = Suma, Boolean + Number = Suma, Boolean + Boolean = Suma, Number + String = Concatena, String + Boolean = Concatena o String + String = Concatena.

Explicaci贸n basada en 馃憠馃徏 Operadores Aritm茅ticos | Documentaci贸n MDN y C贸mo hacer matem谩ticas en JavaScript con operadores | Blog de Digital Ocean



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment