View Single Post
Old 12-04-2012, 08:38 PM   PM User | #9
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
If you use the keyword var *INSIDE* of a function, then all variables thus defined are accessible *ONLY* in that function.

When you return a value from a function, that return value WILL BE IGNORED unless it is assigned to a variable by the caller or used in some expression by the caller.

So, just for example, when you did
Code:
getvolume(length, width, height);
that call was useless. Because the function declared the variable v inside itself and so it is invisible outside the function *AND* you then ignored the value returned by the function.

A reasonable thing to do would have been something like
Code:
var volume = getvolume(length, width, height);
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote