Advantages of using [] over new Array() in JavaScript

后端 未结 7 664
轻奢々
轻奢々 2020-12-05 10:49

What are the advantages of using

var foo = []; 

over using

var bar = new Array();

i\'ve been told to use

7条回答
  •  旧时难觅i
    2020-12-05 11:31

    Both can be used as good. This discussion/confusion has started since Javascript guru Douglas Crockford told that the new keyword is considered harmful. Since then it was considered "good practice/technique" to leave out the new keyword to avoid unexpected results/behaviour. Also see this Stackoverflow topic.

提交回复
热议问题