Basic JavaScript - Assignment with a Returned Value

Hello, so my question is why is it that the num argument is in parentheses when used in a return statement? Previous lessons taught me to use it as is (no parantheses). Is it because of + 3? if so why in parantheses? Please help me understand. Thanks!!!
Your code so far

// Setup
let processed = 0;

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

// Only change code below this line

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 Edg/117.0.2045.31

Challenge: Basic JavaScript - Assignment with a Returned Value

Link to the challenge:

This case is not related to return itself. Without parentheses - num + 3 / 5 - it would have different result, as the division would be calculated before num value is added.

So when we do calculation more than one, the first calculation has to be in parentheses?

It doesn’t need to be. Unless not adding parenthesis would cause wrong result. This might sound a bit vague, but the main factor is the operator precedence and what would be the intended result. With num added to 3 first and then divided by 5 - written as (num + 3) / 5; or 3 divided by 5 and then added to num - written as num + 3 / 5

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