3

I have read lots of paragraphs on w3schools that are telling us to avoid "new" when there is an another option. "new" Keyword is easy to use so why are they telling us to avoid it? What are the advantages of using literals?

var family = [
new Person("Bob",13),
new Person("Bo0",103),
new Person("hfg",163),
new Person("timmy",6)
]

instead of this

var family = new Array();
family[0] = new Person("alice", 40);
family[1] = new Person("bob", 42);
family[2] = new Person("michelle", 8);

which one is better or wise?

English is not my native. Please correct mistakes if possible.

Thanks.

DifferentPseudonym
  • 1,004
  • 1
  • 12
  • 28
  • 10
    I could show you lots of paragraphs on why you should avoid w3schools. Use MDN for your reading material: https://developer.mozilla.org/en-US/docs/Web – Oka Apr 19 '15 at 17:41
  • 2
    [w3schools is not a good resource to the point that w3fools was created to specificially counter it](http://www.w3fools.com/). – zzzzBov Apr 19 '15 at 17:41
  • 1
    Lots of things to say - but lets start by pointing out that you have `new`in BOTH your examples. So what is this talk about "avoidance"? Anyway, see here: http://stackoverflow.com/questions/5224295/javascript-the-good-parts-how-to-not-use-new-at-all/5224405#5224405 – Mörre Apr 19 '15 at 17:42
  • Yes, it's better to avoid `new Array` and use `[]`. – dfsq Apr 19 '15 at 17:47

0 Answers0