w3schoon Posted February 17, 2013 Share Posted February 17, 2013 (edited) Nice be with you everyone! While reading http://www.w3schools...s_obj_array.asp I've noticed two confusing arrays... 2: Condensed: var myCars=new Array("Saab","Volvo","BMW"); 3: Literal: var myCars=["Saab","Volvo","BMW"]; My question is: What is the difference between Literal arrays & Condensed Arrays? & which of them is better to use? Thank you. Edited February 17, 2013 by w3schoon Link to comment Share on other sites More sharing options...
Ingolme Posted February 17, 2013 Share Posted February 17, 2013 No difference.A literal array is shorter which means it saves bandwidth. It is probably a bit more efficient in most browsers. Link to comment Share on other sites More sharing options...
callumacrae Posted February 17, 2013 Share Posted February 17, 2013 a = [3]; // [3]a = new Array(3); // [ , , ] They behave differently. You should only use an array literal unless you specifically want to create an array of a certain length (useful for making a string with 50 instances of a word, for example.) There are a few reasons for this; it is cleaner, the Array variable can be overwritten, no need for scope resolution which makes it more efficient, and no strange behaviours that you need to worry about. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now