By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,278 Members | 2,254 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,278 IT Pros & Developers. It's quick & easy.

inefficient to check value of a checkbox?

P: n/a
I have a big loop that checks the value of a checkbox several times
(1000+ times)
I'm just wondering, would it be any more efficient to save the value of
the checkbox outside the loop and the read that variable inside the
loop instead?

ie, I have this
for (var i=0;...)
doStuff (form1.checkbox1.checked);
versus
var chk = form1.checkbox1.checked;
for (var i=0;...)
doStuff (chk);

May 26 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Kourosh said the following on 5/26/2006 2:54 PM:
I have a big loop that checks the value of a checkbox several times
(1000+ times)
I'm just wondering, would it be any more efficient to save the value of
the checkbox outside the loop and the read that variable inside the
loop instead?

ie, I have this
for (var i=0;...)
doStuff (form1.checkbox1.checked);
versus
var chk = form1.checkbox1.checked;
for (var i=0;...)
doStuff (chk);


Do the second. It keeps from having to look up that property 1000 or so
times and as such will *always* be faster.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 26 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.