Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

wei du
wei du
2,569 Points

4/3

since 4/3 === (4/3) and the 4/3 is calculated in the beginning of the functions below:

function volSphere(radius){
  return (4/3) * Math.PI * Math.pow(radius, 3);
}

is it still necessary for the me to put parentheses around it? or it is just the best practice?

1 Answer

From MDN: "The grouping operator ( ) controls the precedence of evaluation in expressions."

You code returns the same results whether you use parenthesis or not, because the operation precedence would be the same in this case with or without them. If the operator had a lower precedence, you would need the parenthesis to ensure the calculation would be correct.

See also: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence