mgraham Posted October 9, 2014 Share Posted October 9, 2014 Is it considered poor practise to use many temporary variables to store in-progress values like this: ts = document.getElementById("1s-quantity").value; quantity1s = Number(ts); when one could compress that into quantity1s = Number(document.getElementbyId("1s-quantity").value); I use a lot of temporary variables so that I can see what is going on step by step when I'm debugging. When the code works I generally don't bother compressing it again, and I'm just curious whether there is any good reason to. Mike Link to comment Share on other sites More sharing options...
Ingolme Posted October 9, 2014 Share Posted October 9, 2014 There's no problem with using extra variables, code readability is important so if that helps you it's good. There is a problem with forgetting to declare variables with the var keyword because it will actually have an effect on the program that's running. Link to comment Share on other sites More sharing options...
justsomeguy Posted October 9, 2014 Share Posted October 9, 2014 If you don't want to have the extra variables, then just use the same one: quantity1s = document.getElementById("1s-quantity").value;quantity1s = Number(quantity1s); Link to comment Share on other sites More sharing options...
riyaz123 Posted October 10, 2014 Share Posted October 10, 2014 There's no problem with using extra variables, code readability is important so if that helps you it's good. There is a problem with forgetting to declare variables with the var keyword because it will actually have an effect on the program that's running. Yes, I,m agree with ingolme. It will surely create problem without var keyword. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now