Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialEdward Ulick
2,756 PointsArray literal
What is an "array literal," mentioned at 4:36 in the video?
2 Answers
alastair cooper
30,617 PointsAn array literal is an array that is declared in your code, as opposed to being created dynamically when your code runs.
ie I could declare var arr = ['value1' , 'value2' , 'value3']
This is an array literal.
You will see the same thing with objects
ie
var obj = { name: 'myName' }
however, the statement ...
var obj = new OBJECT('myName')
creates the object in memory dynamically when the code is run, instead of me 'literally' declaring it in my code.
Hope this helps
Alastair
Steven Parker
231,269 PointsIt's just an array that is contained in your code. Here's an example of assigning a variable using an array literal:
var myArray = [ "one", "two", "three" ]; // this array has 3 strings
Edward Ulick
2,756 PointsThanks Steven!
Edward Ulick
2,756 PointsEdward Ulick
2,756 PointsThanks Alastair!