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?

  • $\begingroup$ This doesn't seem to be about CS education at all... Am I mistaken? $\endgroup$
    – ItamarG3
    Commented May 29, 2018 at 20:57
  • $\begingroup$ This is about how best to teach and explain a CS concept... $\endgroup$
    – WalkerLJ
    Commented May 29, 2018 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
    Commented May 29, 2018 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$ Commented May 30, 2018 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$ Commented May 30, 2018 at 14:50

1 Answer 1


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.


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