Could you explain in detail what means return?

Could you explain in detail what means return?
0

#1


#2

The return statement says what the function outputs as value (and mark the end of the function). So not sure if this is clear example (and if this is what you mean), but consider the following example:

function returnSomething(){
  // do something
  return 5;
}

var x = returnSomething();

Basically the return statement determines what the value of x is. (5, in this case).

http://www.w3schools.com/jsref/jsref_return.asp


#3

What mean : in return ?


#4

Return means that the function returns some value to the caller and finishes it’s work. Since it “gives” a value to it’s caller, this value can be stored in variable.


#5

I know what return means, I asking what means this double points between “Bet” and “Hold” - :


#6

#7

Thank you very much. I guess I understand.


#8

It’s like a condensed if-else block that you can use in an expression.

return count + (count > 0 ? " Bet" : " Hold");

is the same as

if (count > 0)
  return count + " Bet";
else
  return count + " Hold";

#9

Does anybody have a way to use the ternary only for that true part ? Say I don’t have an else statement but like the simplicity of the ternary operator over a whole if/else block ?

Can we do something like :

return true ? true : null;


#10

I can’t think of anything other than just going for an if-statement:
if (true) return true;

It’s probably clearer this way compared to having a floating null in there.


#11

I had a lot of trouble with this exercise as well. The instructions are rather vague.