2
$\begingroup$

I am familiar with the concept of void and return methods in Java, and am teaching a course in JavaScript, programming Sphero robots. I think I have the gist of how to explain these concets, but am slightly concerned since I can't find any good examples of NON- return (void) functions used in the JavaScript. It seems that the keyword 'void' is only used to indicate an expression without a return value. The problem is, I need to differentiate between void and return methods/functions since you cannot use an Async function with a return function.

Is this concept of void and return methods in Java analogous to JavaScript as well, or is there a better keyword that I can use to explain the different kinds of functions?

Another thing I would like to explain, is, what if you are calling a function, but you don't know what was coded to create it? Is there a hard and fast rule or way to tell if something is void or return?

$\endgroup$

closed as off-topic by ItamarG3, Buffy, Gypsy Spellweaver, thesecretmaster May 30 '18 at 11:16

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be about Computer Science education, within the scope defined in the help center." – ItamarG3, Buffy, thesecretmaster
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ This doesn't seem to be about CS education at all... Am I mistaken? $\endgroup$ – ItamarG3 May 29 '18 at 20:57
  • $\begingroup$ This is about how best to teach and explain a CS concept... $\endgroup$ – WalkerLJ May 29 '18 at 21:11
  • 1
    $\begingroup$ Would you mind adding some examples of the functions you're talking about? I also think @ItamarG3 may have been noticing that you seem to be asking for the concept to be explained to you, and not to be asking for ways to teach a concept you already know. That's not necessarily a bad thing though. $\endgroup$ – thesecretmaster May 29 '18 at 21:15
  • 2
    $\begingroup$ JavaScript ≇ Java ₗᵢₜₑ ! In JavaScript void is not a type, it is an unary operator which evaluates to undefined. In addition, every function in JavaScript returns something, even if that is undefined. An async function will return a Promise, even if that function has a return statement in it which returns a regular value. So, what is the real question/problem you need answered/addressed? $\endgroup$ – Gypsy Spellweaver May 30 '18 at 2:57
  • 2
    $\begingroup$ A function that has no return value, is not a function. It is a procedure. However the C family (C, C++, Java, C#, JS, ;..) of languages call them all functions by mistake. A good was to distinguish is with good names. Verb phrases for procedures (no-return), adjectives if returning boolean, nouns if returning something else. Not foolproof, as any fool can use bad names. $\endgroup$ – ctrl-alt-delor May 30 '18 at 14:50
1
$\begingroup$

A function to perform a procedure often has a void return type. For example:

function foo(a, b, s)
{
    // tell sphero s to go one direction a, another b
}

You are executing a procedure as a side effect and are not returning a computed value.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.