Help, i dont get the word "return"

Tell us what’s happening:
Describe your issue in detail here.
Im getting confused with the word “return”

  **Your code so far**
// Setup
let processed = 0;

function processArg(num) {
return (num + 3) / 5;

// Only change code below this line
processed = processArg(7); 
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Assignment with a Returned Value

Link to the challenge:

Can you explain a little more about what you don’t understand?

let processed = 0;

function processArg(num) {
return (num + 3) / 5;

the word return, i dont get it. I dont get how it function .

Did you complete this lesson?

Return a Value from a Function with Return

yes, i did but, i dont quite get how it works.

It is the output of a function, its result

The return statement causes the function to exit immediately and return the value of the expression in the return statement.

return 5;

This causes the function to exit and return the number 5. In your function processArg, the return statement will evaluate the expression (num + 3) / 5 and then return the value of that expression.

processed = processArg(7); 

This means the return statement is:

return (7+3) / 5;

So the function will return the value 2 and the variable processed will be set to the returned value.

Great explanation above!

‘return’ is a JavaScript keyword that tells the function what to send back to you. And once it’s sent something back to you, it know to stop running that function.

You put things into a function. And you want the function to send something different back to you. ‘return’ is how it knows what you want sent back out of the function. And once the system encounters the ‘return’ keyword, it’ll send you what you asked for, and then it will stop running the function.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.