[Javascript] Single vs. Double quotes in Javascript

Peter-Paul Koch gassinaumasis at hotmail.com
Fri Nov 14 08:07:32 CST 2003


>liorean wrote:
>>And the test:
>>javascript:var a=50,b=[];while(a--)b.push((function(){var i=new 
>>Date,t=5e4,s='';while(t--)s+='text';return (new 
>>Date-i);})());while(b.length>1)b[0]+=b.pop();b/=50; // Substitute single 
>>for double quotes to get the double quote test
>>
>>(I tried to run the test code in ie6w and saf1.0 both, but the browsers 
>>just stopped responding each time I did that, so I have no test results 
>>from there...)
>
>It doesn't stop, actually. But Moz is *billions* (he he) times faster than 
>IE on these string operations, and you get the impression that IE hangs. 
>Just wait it out, if you want to see some really sad performance.

Yes, that's interesting.

>I stand corrected regarding the single versius double quote performance 
>claim. Sorry about that, I'll check my sources better the next time.
>
>I still want to know the "true" difference between single and double 
>quotes, though. If any.

None at all. They are exactly the same, except that you'll have to use the 
same kind of quote to close a string as you used to open it.

I myself use single quotes in JavaScript and double quotes in HTML, but 
that's just a convention. It has no redeeming features whatsoever, and doing 
it the other way around is just as good.

Making some sort of rule as to which quotes you use where is very useful, 
though. It'll keep you from becoming confused.

-------------------------------------------------------------------
ppk, freelance web developer
Interaction, copywriting, JavaScript, integration
http://www.quirksmode.org/
Column "Keep it Simple": http://www.digital-web.com/columns/keepitsimple/
------------------------------------------------------------------

_________________________________________________________________
Talk with your online friends with MSN Messenger http://messenger.msn.nl/




More information about the Javascript mailing list