Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

What is the difference between these 2 JavaScript functions using return?

$
0
0

So I'm learning JS, regarding functions and the use of return. Is there a functional difference between these 2 functions? They are both supposed to be BMI calculators. I've tested them out, and the first one works once you call the function and set a weight/height.

1.)

function bmiCalculator(weight, height){    return bmi = Math.round(weight / Math.pow(height, 2));} 

2.)

function bmiCalculator(weight, height){    var bmi = Math.round(weight / Math.pow(height, 2));    return bmi;}

1.) works once I call function:

bmiCalculator(65, 1.8);

shows 20 on console

2.) works once I code:

var bmi = bmiCalculator(65, 1.8);console.log(bmi);

shows 20 on console


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>