Data Structures: Arrays and Objects

In Unit 3, you learned about JavaScript primitive data types such as strings, numbers, and Booleans. In addition, this unit introduces the "array" and "object" data types. 

Why use objects?

  • Objects are an essential data type of JavaScript, and learning how to use them is necessary to develop applications.
  • Objects help programmers write reusable code for real-world objects. 
  • Objects are dynamic; you can create, add, and delete them.

"On two occasions I have been asked, 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' [...] I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question".

 – Charles Babbage, Passages from the Life of a Philosopher (1864)


Numbers, Booleans, and strings are the atoms that data structures are built from. Many types of information require more than one atom, though. Objects allow us to group values – including other objects – to build more complex structures.

The programs we have built so far have been limited by the fact that they were operating only on simple data types. This chapter will introduce basic data structures. By the end of it, you'll know enough to start writing useful programs.

The chapter will work through a more or less realistic programming example, introducing concepts as they apply to the problem at hand. The example code will often build on functions and bindings that were introduced earlier in the text.



Source: Marijn Haverbeke, https://eloquentjavascript.net/04_data.html
Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial 3.0 License.