Answers.Body: <p>A function to perform a procedure often has a void return type. For example:</p>
  
  <pre><code>function foo(a, b, s)
  {
      // tell sphero s to go one direction a, another b
  }
  </code></pre>
  
  <p>You are executing a procedure as a side effect and are not returning a computed value.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-30T00:08:31.757Z
Answers.LastActivityDate: 2018-05-30T00:48:50.563Z
Answers.LastEditDate: 2018-05-30T00:48:50.563Z
Answers.UserDisplayName: ncmathsadist
Body: <p>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.</p>
  
  <p>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?</p>
  
  <p>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?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-29T20:57:13.087Z
Comments.Text: This doesn't seem to be about CS education at all... Am I mistaken?
Comments.UserDisplayName: ItamarG3
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-29T21:11:42.963Z
Comments.Text: This is about how best to teach and explain a CS concept...
Comments.UserDisplayName: WalkerLJ
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-29T21:15:01.393Z
Comments.Text: 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.
Comments.UserDisplayName: thesecretmaster
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-29T21:44:20.223Z
Comments.Text: thanks! Here's the docs for the sphero; https://sphero.docsapp.io/docs/Production%2010-05-2017/12-advanced-concepts#keywords-async-and-await. It has some examples
Comments.UserDisplayName: WalkerLJ
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-30T02:57:07.840Z
Comments.Text: **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?
Comments.UserDisplayName: Gypsy Spellweaver
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-30T11:16:51.753Z
Comments.Text: I've thought about this question a bit more, and it really seems like a programming question rather than a teaching question. That's why I've voted to close as off-topic. If it is a teaching question, please [edit] it to clarify. If not, you might have better luck asking on Stack Overflow.
Comments.UserDisplayName: thesecretmaster
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-30T14:50:25.717Z
Comments.Text: 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.
Comments.UserDisplayName: ctrl-alt-delor
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-31T04:07:52.407Z
Comments.Text: @GypsySpellweaver, I know that async methods return promises, but promises don't count as true return methods. This is the concept I am struggling to explain- if you look at the docs here; https://sphero.docsapp.io/docs/12-advanced-concepts#keywords-async-and-await you can see that it says you can't return values with async functions, and you shouldn't use them with it. What is the distinction, and how can I explain it?
Comments.UserDisplayName: WalkerLJ
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-31T04:08:41.823Z
Comments.Text: @ctrl-alt-delor the unfortunate thing is in JS, as far as I can tell, all methods are called functions? so where is the distinction? I want to help students create async functions with Sphero, and want to make a clear distinction. What is that distinction?
Comments.UserDisplayName: WalkerLJ
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-31T05:47:47.800Z
Comments.Text: That distinction is a red herring: it does not exist. To repeat: _ALL_ functions (methods) in JS _return_ something, whether or not the programmer tells it to, and whether or not the caller uses it. The docs are not 100% correct: Point #2 is advice, not compiler law, Point #3's title does not match its text. A compile error is given when `await` is used inside a function not declared `async` but an `async` function can return a value and be valid to the compiler.
Comments.UserDisplayName: Gypsy Spellweaver
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-31T16:09:36.873Z
Comments.Text: @GypsySpellweaver, Depends whether you are talking about computer science education or job training.  If you're talking about computer science, then "procedure" and "function" have accepted meanings, independent of any particular programming language.
Comments.UserDisplayName: Solomon Slow
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-31T17:17:19.770Z
Comments.Text: @jameslarge The fact that procedure and function have a distinct, and separate, meaning in computer science is why the distinction is a red herring in JavaScript. JavaScript does not implement "procedures" _everything_ is a "function" and will always return _something_, even if nothing is specified, or if the return value is disregarded. The programmer can code it like a procedure, and call it like a procedure, but in JS it is still a "function."
Comments.UserDisplayName: Gypsy Spellweaver
Tags: <javascript><methods>
Title: Best Way to Explain Distinction Between Void vs. Return Functions in JavaScript
ThreadText: # Best Way to Explain Distinction Between Void vs. Return Functions in JavaScript
  
  (Asked by: username_0 on 2018-05-29)
  
  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?
  
  **Tags:** javascript, methods
  
  > **Comments:**
  > **username_1**: This doesn't seem to be about CS education at all... Am I mistaken?  
  > **username_0**: This is about how best to teach and explain a CS concept...  
  > **username_2**: Would you mind adding some examples of the functions you're talking about? I also think @username_1 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.  
  > **username_0**: thanks! Here's the docs for the sphero; https://sphero.docsapp.io/docs/Production%2010-05-2017/12-advanced-concepts#keywords-async-and-await. It has some examples  
  > **username_3**: **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?  
  > **username_2**: I've thought about this question a bit more, and it really seems like a programming question rather than a teaching question. That's why I've voted to close as off-topic. If it is a teaching question, please [edit] it to clarify. If not, you might have better luck asking on Stack Overflow.  
  > **username_4**: 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.  
  > **username_0**: @username_3, I know that async methods return promises, but promises don't count as true return methods. This is the concept I am struggling to explain- if you look at the docs here; https://sphero.docsapp.io/docs/12-advanced-concepts#keywords-async-and-await you can see that it says you can't return values with async functions, and you shouldn't use them with it. What is the distinction, and how can I explain it?  
  > **username_0**: @username_4 the unfortunate thing is in JS, as far as I can tell, all methods are called functions? so where is the distinction? I want to help students create async functions with Sphero, and want to make a clear distinction. What is that distinction?  
  > **username_3**: That distinction is a red herring: it does not exist. To repeat: _ALL_ functions (methods) in JS _return_ something, whether or not the programmer tells it to, and whether or not the caller uses it. The docs are not 100% correct: Point #2 is advice, not compiler law, Point #3's title does not match its text. A compile error is given when `await` is used inside a function not declared `async` but an `async` function can return a value and be valid to the compiler.  
  > **username_5**: @username_3, Depends whether you are talking about computer science education or job training.  If you're talking about computer science, then "procedure" and "function" have accepted meanings, independent of any particular programming language.  
  > **username_3**: @jameslarge The fact that procedure and function have a distinct, and separate, meaning in computer science is why the distinction is a red herring in JavaScript. JavaScript does not implement "procedures" _everything_ is a "function" and will always return _something_, even if nothing is specified, or if the return value is disregarded. The programmer can code it like a procedure, and call it like a procedure, but in JS it is still a "function."  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_6 on 2018-05-30. Score: 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.
  
  
  ---
  
  