views:

703

answers:

6

Is it better for sake of compatibility/JIT-Compiling performance to use UPPER CASE or lower case, in JS/HTML? For eg:

 <DIV> my content </DIV>
 <div> my content </div>

 ALERT(DOCUMENT.LOCATION);
 alert(document.location);

This is not a newbie question, I know lowercase is the de-facto standard. But since I've seen some uppercase JS+HTML, I was wondering which would be better to write in. (like SQL is fully uppercase?)

+4  A: 

I don't think it'd make a difference, speed-wise.

XHTML: Lowercase tags is what the W3C specified.

JavaScript: It probably wouldn't work, because I have never seen anyone's code use all caps in JS.

SQL is fully uppercase to differentiate the actions, functions, etc from the actual data. You can use lowercase, but it becomes less readable (to some, me included).

IMO, wading through a heap of uppercase tags is less readable than lowercase tags. I'd say user agents don't care what case the tags are. Here's a little bit of history: when I made a website in 1999, uppercase tags were the standard.

You can still find some dodgy non updated websites out there that still write

'Use <B></B> to make text bold'

alex
XHTML was 10 years ago. That should ensure widespread browser support.
Jenko
Wow, that got accepted quick!
alex
"I don't think it'd make a difference." You might want to specify that you mean HTML there, not Javascript.
Anonymous
Thanks Anon, answer updated.
alex
@Jeremy You would think, but Internet Explorer still doesn't support it (except in "This is HTML with syntax errors" mode). Give it application/xhtml+xml and it will ask if you want to open it in another application or save it.
David Dorward
+2  A: 

It is incorrect (in xhtml, at least) to use <DIV>...</DIV>; it is a <div>...</div>.

Likewise, I'd use lower-case in the javascript (for alert(document.location);), as that is their names ;-p

Marc Gravell
+1  A: 

I can't imagine it making any difference compatibility- or performance-wise. I think some people find UPPERCASE easier to recognize as markup or code rather than content.

You can do some benchmarks, if you must.

(XHTML specifies lowercase as the standard, so if your goal is satisfying validators, then go with that)

pyrochild
A: 

It certainly makes a difference with javascript since it is case sensitive.

The accepted community standard for html is lowercase, even though browser don't care.

So be nice to the ones who have to read your code later!

Chad Grant
A: 

I'd definitely go with lowercase wherever possible. I tend to like camel casing multi-word variable names, but even that can be eschewed in favor of underscores.

Evan Meagher
+1  A: 

JavaScript is (using Fx3.0) case sensitive.

var myURL = document.URL; // sets myURL to the current URL
var myURL2 = DOCUMENT.URL; // ReferenceError: "DOCUMENT" is not defined

HTML allows mixed-case tags, XHTML demands lower-case only tags, attributes.

mattoc