I see code like this all over the web
var days= "Monday Tuesday Wednesday Thursday Friday Saturday Sunday".split(" ");
Why do that instead of
var days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
I don't think laziness or ignorance has anything to do with it. This is out of jQuery 1.4.2
props: "altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode layerX layerY metaKey newValue offsetX offsetY originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" ")
They do it all over the place.
I think it's because you don't have to quote and separate every string of the array. Likewise, in perl, many people use qw(a b c d e f g)
instead of ('a', 'b', 'c', 'd', 'e', 'f', 'g')
. So the benefit is twofold:
See the bit size:
var days= "Monday Tuesday Wednesday Thursday Friday Saturday Sunday".split(" ");
// 81 characters
vs
var days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
// 91 characters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With