Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

431
Vistas
What does it mean that "Expression returns values" in programming?

What does "Operators return values" in programming? I mean, take the + operator. If we have 2 numbers (not strings)as operands, it sums the operands togheter. But what does it mean that it returns a value? Isn't is just supposed to sum two numbers togheter?

I really don't get what this "return" mean, the value is returned to...who/what/where?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

the value is returned to...who/what/where?

To whatever did evaluate the expression, or put otherwise, whatever did want the interpreter to evaluate the expression. Just like a function returns a value to its caller, the interpreter returns the result of the evaluation. Don't overthink it.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Think of it in terms of speaking. When you speak, you can make a statement, as in: "I'm hungry." This would not require a "response" from the other person in the conversation, but if I said "Are you hungry?", I would expect a response.

In other words sometimes the statements you write are just instructions to be followed that don't result in any "response" from the system, but others do and those responses are what we call the "return value" of the statement.

So, 1 + 1 is something that returns a value - - the system will carry out the command and a new value will be the result. That new value is the return value. Now, you need to know what kinds of statements do return values and which don't so you can decide if you want to capture that returned value and/or do something with it.

 1 + 1  // 2 will be returned from this, but the code doesn't capture it

 foo = 1 + 1  // Now the 2 will be returned and captured for future use by the program

But, console.log("Hello") is an instruction that will be carried out and no response (return value) will be generated. So, it wouldn't make any sense to write:

 foo = console.log("Hello");

Because nothing is returned from console.log(), so foo would wind up being undefined even though the message would still be written to the console.

In fact, if you aren't sure if a statement will or won't return a value, you can find out by trying to assign a variable to the result and then checking the variable:

let foo = console.log("Hello");  // Hello
console.log(foo);                // undefined   


let bar = 1 + 1;
console.log(bar);  // 2

As you can see, when there is a return value, the statement that caused it is the statement that decides whether to capture it or not - - the return value is returned as a result of the statement. So, as discussed earlier in this answer, the statement 1+1 will cause the system to do the math and return the answer to the code context that spawned the action in the first place, but that statement isn't prepared to receive the response and so the response is never captured and, for all intents and purposes, is gone. But foo = 1 + 1 is prepared for the return value by saying that foo should store or capture the return value from executing the statement 1+1.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda