Skip to content

Instantly share code, notes, and snippets.

@teffcode
Created May 6, 2020 14:12
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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