Jump to content

The use of temporary variables


mgraham

Recommended Posts

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...