jtified Posted August 25, 2009 Report Posted August 25, 2009 (edited) Hi there! I'm a beginner when it comes to programming thats why I want to know what ARE the differences of declaring a variable like this: function function_name(var1,var2,...,varX) { some code } TO this: function function_name() { var1; var2; varX; etc....... some code } Edited August 25, 2009 by jtified Quote
falkencreative Posted August 25, 2009 Report Posted August 25, 2009 The difference between the two depends on how you intend to use the Javascript function. When declaring your variables inside the function, like example #2 above, the variable will always hold one particular value. For example, function function_name() { var1 = 1; some code; } When that variable is inside the function, it will always hold the value of 1 (unless you make changes to the value later in the function). In example #1, the way the javascript is written allows you to give different values to the variables depending on how you call the function. For example, function function_name(var1) { some code } you could call that function, using different values for the variable each time: function_name(2); function_name(455); In line #1, the "var1" variable would equal 2, and in line 2, it would equal 455. Quote
jtified Posted August 26, 2009 Author Report Posted August 26, 2009 I understand now. Thank you for that! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.