{"id":14802,"date":"2018-03-30T17:22:33","date_gmt":"2018-03-31T00:22:33","guid":{"rendered":"https:\/\/www.podfeet.com\/blog\/?page_id=14802"},"modified":"2018-04-03T07:37:39","modified_gmt":"2018-04-03T14:37:39","slug":"objects-in-javascript","status":"publish","type":"page","link":"https:\/\/www.podfeet.com\/blog\/tutorials-5\/objects-in-javascript\/","title":{"rendered":"How almost everything in JavaScript is an Object &#8211; by Will aka @beiju"},"content":{"rendered":"<p>The following explanation is from an old friend of the show, Will (also known as @beiju).  Unbeknownst to us, he&#8217;s been following along with Programming By Stealth all this time and just popped his head up for the first time in quite a few years.  <\/p>\n<p>Will wrote the following in an email to Bart and me:<\/p>\n<blockquote><p>In recent episodes Allison has been audibly frustrated about objects. I noticed a disconnect in Allison&#8217;s understanding of objects that I think is causing all of this. I wrote up a short explanation (at least, it was short when I started) that I think will close the gap. I attached it as an HTML document, complete with imperfect syntax highlighting and tiny font to make you feel at home. It&#8217;s written in a conversational style talking directly to Allison. I start with restating things that I think you (Allison) are already comfortable with and take a series of small steps, each with some code examples that you can use to prove that I&#8217;m telling the truth, until I arrive at the link that Allison&#8217;s missing. <\/p><\/blockquote>\n<p>I liked it enough I wanted to make sure it was shared with the entire Programming By Stealth family.  So here is Will&#8217;s fantastic explanation of objects.<\/p>\n<p><!--more--><\/p>\n<hr>\n<p>I\u2019m going to attempt to reconcile the two <i>correct<\/i> definitions of a JavaScript object that we\u2019ve heard: \u201ca collection of name-value pairs\u201d and \u201canything that isn\u2019t a boolean, a number, or a string\u201d. I\u2019ll start with the one I think you\u2019re more comfortable with &mdash; name-value pairs &mdash; and take small steps until we get to the other one.<\/p>\n<p><\/p>\n<p>So, an object is a collection of key-value pairs. The first thing to look at is, how do we make one? There are a few ways (you may not believe that yet, but I will convince you), but let\u2019s start with the one we are more familiar with: the <b>object literal<\/b>. \u201cObject literal\u201d is just the official name for this syntax:<\/p>\n<p><\/p>\n<pre><code class='code-multiline'><span class=\"sf_code_syntax_keyword\">const<\/span> myObj <span class=\"sf_code_syntax_keyword\">=<\/span> {\r\n\t<span class=\"sf_code_syntax_string\">\"some key\"<\/span>: <span class=\"sf_code_syntax_string\">\"some value\"<\/span>,\r\n\t<span class=\"sf_code_syntax_string\">\"some other key!\"<\/span>: <span class=\"sf_code_syntax_number\">true<\/span>,\r\n\t<span class=\"sf_code_syntax_string\">\"3rd key\"<\/span>: <span class=\"sf_code_syntax_number\">42<\/span>\r\n}<\/code><\/pre>\n<p><\/p>\n<p>The keys are always strings (always, for any object), and the values can be anything. JavaScript also gives us a shortcut: if the keys follow all the rules for a valid variable name, we can leave out the quotes. Here\u2019s almost the same object with the keys modified so they\u2019re valid variable names.<\/p>\n<p><\/p>\n<pre><code class='code-multiline'><span class=\"sf_code_syntax_keyword\">const<\/span> myObj <span class=\"sf_code_syntax_keyword\">=<\/span> {\r\n\t<span class=\"sf_code_syntax_character\">someKey<\/span>: <span class=\"sf_code_syntax_string\">\"some value\"<\/span>,\r\n\t<span class=\"sf_code_syntax_character\">someOtherKey<\/span>: <span class=\"sf_code_syntax_number\">true<\/span>,\r\n\t<span class=\"sf_code_syntax_character\">key3<\/span>: <span class=\"sf_code_syntax_number\">42<\/span>\r\n}<\/code><\/pre>\n<p><\/p>\n<p>I had to get rid of all the spaces and the exclamation mark, because they\u2019re not allowed in variable names. I also had to move the digit 3 to the end of the third key, because variable names can\u2019t <i>start<\/i> with numbers.<\/p>\n<p><\/p>\n<p>So now we have an object. An object made this way, by specifically listing out its names and values inside squiggly brackets, is often called a <b>plain object<\/b>. I\u2019ll show you what\u2019s plain about it when I talk about other objects. <\/p>\n<p><\/p>\n<p>Now, what are the things we can do with an object? First, we can get the value associated with a particular name. We do that with the square bracket operator, like this:<\/p>\n<pre><code class='code-multiline'><span class=\"sf_code_syntax_keyword\">const<\/span> theValue <span class=\"sf_code_syntax_keyword\">=<\/span> myObject[<span class=\"sf_code_syntax_string\">\"some name\"<\/span>]\r\n<\/code><\/pre>\n<p>This might be the first sticking point, because you\u2019re used to using the square brackets with arrays, to ask the question \u201cwhat value is at this position in the array?\u201d. Your understanding is <i>correct<\/i>, but not <i>complete<\/i>. <b>Square brackets immediately after a variable name will get a specific value out of any collection of values.<\/b> With arrays, the way we identify a specific value is by its position, so we put the position inside the square brackets. But with objects, we identify a specific value by its name, so we put the name inside the square brackets. Same concept, but applied in a different context.<\/p>\n<p><\/p>\n<p>As an aside, you don\u2019t need to put a literal string (a string inside quote marks) in the brackets. You can put anything there that Javascript can turn into a string. <code class='code-inline'>myObject[\"some name\"]<\/code> gets the value associated with the name \u201csome name\u201d, just like <code class='code-inline'>myArray[0]<\/code> gets the value at position 0. But you can put a variable in there, too: <code class='code-inline'>myObject[someVariable]<\/code> gets the value associated with whatever name is stored in the variable <code class='code-inline'>someVariable<\/code>, just like <code class='code-inline'>myArray[i]<\/code> gets the value at whatever position is stored in the variable <code class='code-inline'>i<\/code>. And <code class='code-inline'>myObject[stringOne + stringTwo]<\/code> will first figure out what <code class='code-inline'>stringOne + stringTwo<\/code> means, then get the value associated with whatever name that turns out to be, just like <code class='code-inline'>myArray[i + 1]<\/code> first figures out what the value of <code class='code-inline'>i + 1<\/code> and then gets the value at whatever position that turns out to be. That\u2019s not really necessary to explain objects but it is something that I noticed Bart didn\u2019t call attention to, so I thought it was worth saying.<\/p>\n<p><\/p>\n<p>Anyway, back to accessing name-value pairs within objects. Javascript once again gives you a shortcut. If you know the actual name you want, <i>and<\/i> it follows the rules for variable names, you can use the dot syntax instead of square brackets:<\/p>\n<pre><code class='code-multiline'><span class=\"sf_code_syntax_keyword\">const<\/span> theValue <span class=\"sf_code_syntax_keyword\">=<\/span> myObject.someName\r\n<\/code><\/pre>\n<p>That is <i>exactly<\/i> equivalent to this:<\/p>\n<pre><code class='code-multiline'><span class=\"sf_code_syntax_keyword\">const<\/span> theValue <span class=\"sf_code_syntax_keyword\">=<\/span> myObject[<span class=\"sf_code_syntax_string\">\"someName\"<\/span>]\r\n<\/code><\/pre>\n<p>The only advantage is that at looks prettier and it\u2019s less typing. The disadvantage is that you can\u2019t use it with a name that doesn\u2019t follow those rules, or a name that\u2019s stored in a variable.<\/p>\n<p><\/p>\n<p>You can do other things with an object too, which I don&#8217;t remember whether Bart has introduced yet. You can modify it, and the way you do that is very similar to getting values out of it. You just put the object name and attached square brackets on the other side of the equals sign:<\/p>\n<pre><code class='code-multiline'>myObject[<span class=\"sf_code_syntax_string\">\"someName\"<\/span>] <span class=\"sf_code_syntax_keyword\">=<\/span> <span class=\"sf_code_syntax_string\">\"a new value\"<\/span>\r\n<\/code><\/pre>\n<p>If there\u2019s already a value associated with the name \u201csomeName\u201d in the object, this will overwrite that value with the string \u201ca new value\u201d. If there isn\u2019t, it adds a new pair with name \u201csomeName\u201d and value \u201ca new value\u201d.<\/p>\n<p><\/p>\n<p>I went over all that because I\u2019m about to show you some other ways to make objects. I expect that you might not believe me at first, but I will prove that those are also objects by showing that you that everything I just talked about works with them, too.<\/p>\n<p><\/p>\n<p>Here is a second way to create an object:<\/p>\n<pre><code class='code-multiline'><span class=\"sf_code_syntax_keyword\">const<\/span> myCow <span class=\"sf_code_syntax_keyword\">=<\/span> <span class=\"sf_code_syntax_keyword\">new<\/span> <span class=\"sf_code_syntax_keyword\">Cow<\/span>()\r\n<\/code><\/pre>\n<p>For this example, I\u2019m using the Cow class that was part of PBS 47 and its associated challenge, the one where we made a farm. I claim that this line of code creates a new object, using the same definition of an object as before: \u201ca collection of key-value pairs\u201d.<\/p>\n<p><\/p>\n<p>Here\u2019s where I prove it. Open the PBS 47 challenge solution in your favorite web browser (the zip file is in <a href=\"https:\/\/www.bartbusschots.ie\/s\/2018\/01\/20\/pbs-48-of-x-a-closer-look-at-this-and-static\/\">PBS 48<\/a>). Open the console and make yourself a new animal using the code snippet above. With <code class='code-inline'>myCow<\/code>, you can:<\/p>\n<ol start=\"1\">\n<li>Get the value associated with a name. <code class='code-inline'>Cow<\/code>s (and all <code class='code-inline'>Animal<\/code>s) all have a value associated with the name <code class='code-inline'>_icon<\/code> (with underscore), so try <code class='code-inline'>myCow[\"_icon\"]<\/code>. You get a value &mdash; it\u2019s an emoji cow. That name also follows the rules for Javascript variable names, so we can equivalently say <code class='code-inline'>myCow._icon<\/code>. And, lo and behold, we get the same thing.\n<\/li>\n<li>Change the value associated with a name. Try <code class='code-inline'>myCow._icon = 12<\/code>, then run <code class='code-inline'>myCow._icon<\/code> again. You just changed it to 12. You could do the exact same thing with <code class='code-inline'>myCow[\"_icon\"] = 12<\/code>.\n<\/li>\n<li>Add a new name-value pair. First, run <code class='code-inline'>myCow.newName<\/code> to demonstrate that it\u2019s not there (which Javascript indicates with the value <code class='code-inline'>undefined<\/code>). Then do <code class='code-inline'>myCow.newName = \"boogers\"<\/code>, and then get the value again. Now <code class='code-inline'>myCow.newName<\/code> should give back <code class='code-inline'>\"boogers\"<\/code>. Once again, you could do all that with the square bracket syntax, too. You can even mix and match dots and square brackets!\n<\/li>\n<\/ol>\n<p><\/p>\n<p>Hopefully that convinces you that <code class='code-inline'>myCow<\/code> is an object. It doesn\u2019t really explain <i>why<\/i> it\u2019s an object, though. For that, think back to when Bart introduced prototypes (<a href=\"https:\/\/www.bartbusschots.ie\/s\/2016\/06\/23\/pbs-17-of-x-js-objects\/\">PBS 17<\/a>). The problem to be solved was that we wanted to make a bunch of similar objects. They would contain the same set of names, but different values. We also wanted to bundle in a bunch of functions that would do useful things to these objects.  Prototypes (which we now also call classes) were a convenient way to build those objects, but at the core, they\u2019re still just a collection of name-value pairs. Even the functions that we bundled in (called \u201cinstance functions\u201d), we bundled as more name-value pairs. You can see this by looking for the functions on <code class='code-inline'>myCow<\/code>. Look at <code class='code-inline'>myCow.getProduce<\/code> in the console &mdash; it\u2019s a function. Add some parentheses on the end to invoke the function, just like how you invoke any function, and you get <code class='code-inline'>myCow.getProduce()<\/code>.<\/p>\n<p><\/p>\n<p>Look familiar? That\u2019s how we\u2019ve been calling functions from our classes the whole time, and it turns out all we were doing was using the dot syntax from objects! We can equivalently say <code class='code-inline'>myCow[\"getProduce\"]()<\/code>, and it does the exact same thing. It\u2019s the same story <i>inside<\/i> the instance functions, too. We\u2019ve been doing things like <code class='code-inline'>this._icon<\/code>, to get an animal\u2019s icon, or <code class='code-inline'>this._grid<\/code> to get the grid of cells in a cellular automation. That\u2019s just the dot syntax to access the properties of the object. (Remember that inside instance functions, <code class='code-inline'>this<\/code> is set to the specific object that the function was called from.) We could equivalently say <code class='code-inline'>this[\"_icon\"]<\/code> or <code class='code-inline'>this[\"_grid\"]<\/code>.<\/p>\n<p><\/p>\n<p>At this point, I\u2019m hoping that something just clicked into place. Hopefully you now believe that class instances are objects the same way plain objects are. <b>Objects made by listing name-value pairs inside squiggly brackets are \u201cplain\u201d. Objects made from a prototype are not.<\/b><\/p>\n<p><\/p>\n<p>Now let\u2019s look at another syntax for creating objects:<\/p>\n<pre><code class='code-multiline'><span class=\"sf_code_syntax_keyword\">const<\/span> myArray <span class=\"sf_code_syntax_keyword\">=<\/span> [<span class=\"sf_code_syntax_number\">false<\/span>, <span class=\"sf_code_syntax_number\">1<\/span>, <span class=\"sf_code_syntax_string\">\"two\"<\/span>]\r\n<\/code><\/pre>\n<p>I\u2019m sure you agree that this makes an array. And arrays are objects, therefore this makes an object. I\u2019m not sure you agree with this one yet, but I will try to prove it.<\/p>\n<p><\/p>\n<p>As Bart has said, the names of all the values in an array are their positions. In the above example, <code class='code-inline'>0<\/code> and <code class='code-inline'>false<\/code>  is one name-value pair, <code class='code-inline'>1<\/code> and <code class='code-inline'>1<\/code> is another, and <code class='code-inline'>2<\/code> and <code class='code-inline'>\"two\"<\/code> is a third. You can access the values using those names: <code class='code-inline'>myArray[0]<\/code> gets the value <code class='code-inline'>false<\/code>, etc. The only reason you can\u2019t use the dot syntax here is that JavaScript variables are not allowed to start with a number. If they were, then <code class='code-inline'>myArray.0<\/code> would be equivalent to <code class='code-inline'>myArray[0]<\/code>.<\/p>\n<p><\/p>\n<p>Arrays also have a length, which is just another name-value pair. <code class='code-inline'>myArray[\"length\"]<\/code> is exactly equivalent to <code class='code-inline'>myArray.length<\/code>. <code class='code-inline'>length<\/code> does have some extra behavior: it updates itself whenever you change the size of the array, and it throws an error if you try to set it to a value that isn\u2019t a number. We could write a class that does the same thing if we wanted to, but it\u2019s very uncommon to need so we haven\u2019t learned how to do it.<\/p>\n<p><\/p>\n<p>In addition to data, arrays also have functions. We\u2019ve seen instance functions, like <code class='code-inline'>someArray.forEach()<\/code> and <code class='code-inline'>someArray.sort()<\/code>, and also static functions like <code class='code-inline'>Array.from()<\/code>. In summary: An array behaves just like an object that was created from a prototype, because it <i>is<\/i> an object that was created from a prototype. <b>An array is just an object with the Array prototype.<\/b> Behind the scenes, whenever you put a bunch of values in square brackets, JavaScript is doing <code class='code-inline'>new Array()<\/code> and then adding all your values to the new Array object. You could build the array that way yourself, if you wanted. This:<\/p>\n<pre><code class='code-multiline'><span class=\"sf_code_syntax_keyword\">const<\/span> myArray <span class=\"sf_code_syntax_keyword\">=<\/span> <span class=\"sf_code_syntax_keyword\">new<\/span> <span class=\"sf_code_syntax_keyword\">Array<\/span>()\r\nmyArray[<span class=\"sf_code_syntax_number\">0<\/span>] <span class=\"sf_code_syntax_keyword\">=<\/span> <span class=\"sf_code_syntax_number\">false<\/span>\r\nmyArray[<span class=\"sf_code_syntax_number\">1<\/span>] <span class=\"sf_code_syntax_keyword\">=<\/span> <span class=\"sf_code_syntax_number\">1<\/span>\r\nmyArray[<span class=\"sf_code_syntax_number\">2<\/span>] <span class=\"sf_code_syntax_keyword\">=<\/span> <span class=\"sf_code_syntax_string\">\"two\"<\/span>\r\n<\/code><\/pre>\n<p>Is exactly equivalent to this:<\/p>\n<pre><code class='code-multiline'><span class=\"sf_code_syntax_keyword\">const<\/span> myArray <span class=\"sf_code_syntax_keyword\">=<\/span> [<span class=\"sf_code_syntax_number\">false<\/span>, <span class=\"sf_code_syntax_number\">1<\/span>, <span class=\"sf_code_syntax_string\">\"two\"<\/span>]<\/code><\/pre>\n<p>\nWe\u2019re nearing the end of the list so I\u2019ll go quicker. Another way to make an object is like this:<\/p>\n<pre><code class='code-multiline'><span class=\"sf_code_syntax_project\">function<\/span> <span class=\"sf_code_syntax_character\">myFunc<\/span>(<span class=\"sf_code_syntax_keyword\">a<\/span>, b) {\r\n\t<span class=\"sf_code_syntax_keyword\">return<\/span> a <span class=\"sf_code_syntax_keyword\">+<\/span> b;\r\n}<\/code><\/pre>\n<p><\/p>\n<p>Yes, functions are objects too! That might be even more surprising than arrays, since normally when we use functions there isn\u2019t a name-value pair in sight! That doesn\u2019t mean they aren\u2019t there, though. Run the above snippet in the browser console, then run <code class='code-inline'>myFunc.name<\/code> &mdash; you get <code class='code-inline'>\"myFunc\"<\/code>! Functions also have a length: <code class='code-inline'>myFunc.length<\/code> is the number of arguments the function has, in this case 2. They\u2019ve got instance functions, too: <code class='code-inline'>myFunc.call<\/code> is a function that we learned about in <a href=\"https:\/\/www.bartbusschots.ie\/s\/2018\/01\/20\/pbs-48-of-x-a-closer-look-at-this-and-static\/\">PBS 48<\/a>. Functions are starting to look an awful lot like objects with prototypes, because they are. In this case the prototype is, unsurprisingly, <code class='code-inline'>Function<\/code>. <\/p>\n<p><\/p>\n<p>The fact that you can call a function with <code class='code-inline'>()<\/code> is a little bit magic, but not as much as you might expect. One of the name-value pairs on a <code class='code-inline'>Function<\/code> instance has a very special name, and the associated value is the code that should run. Any object that has a value associated with that very special name can be called with <code class='code-inline'>()<\/code>. The magic is that the special name is some unspecified string that cannot ever be typed into a computer, so it\u2019s impossible for you to make an object with that name. Only JavaScript itself has the power to make an object with that special name.<\/p>\n<p><\/p>\n<p>There is at least one more example of a prototype that\u2019s given special syntax (a regular expression, for example, which you make with <code class='code-inline'><span class=\"sf_code_syntax_keyword\">const<\/span> myRegExp = \/stuff\/<\/code>), but the idea is always the same: it\u2019s just some special syntax for making an object with a specific prototype (for regular expressions, that\u2019s <code class='code-inline'>RegExp<\/code>). <\/p>\n<p><\/p>\n<p>Before I finish, I want to fix one small white lie I told. I said that a plain object was one that you made with the squiggly brackets syntax, which was true. I also said that an object made from a prototype was not, which isn\u2019t <i>quite<\/i> true. The very first way I introduced for making an object was the squiggly-bracket syntax. Well, the squiggly-bracket syntax is just another special syntax for making an object with a specific prototype! Just like the square brackets that make an array, or the special syntax for making a function. The squiggly-bracket syntax makes objects with the prototype <code class='code-inline'>Object<\/code>.  Like with arrays, you could make them yourself by adding name-value pairs one by one:<\/p>\n<pre><code class='code-multiline'><span class=\"sf_code_syntax_keyword\">const<\/span> myObj <span class=\"sf_code_syntax_keyword\">=<\/span> <span class=\"sf_code_syntax_keyword\">new<\/span> <span class=\"sf_code_syntax_keyword\">Object<\/span>()\r\nmyObj[<span class=\"sf_code_syntax_string\">\"someKey\"<\/span>] <span class=\"sf_code_syntax_keyword\">=<\/span> <span class=\"sf_code_syntax_string\">\"some value\"<\/span>\r\nmyObj[<span class=\"sf_code_syntax_string\">\"someOtherKey\"<\/span>] <span class=\"sf_code_syntax_keyword\">=<\/span> <span class=\"sf_code_syntax_number\">true<\/span>\r\nmyObj[<span class=\"sf_code_syntax_string\">\"key3\"<\/span>] <span class=\"sf_code_syntax_keyword\">=<\/span> <span class=\"sf_code_syntax_number\">42<\/span>\r\n<\/code><\/pre>\n<p>Or equivalently, using the dot syntax:<\/p>\n<pre><code class='code-multiline'><span class=\"sf_code_syntax_keyword\">const<\/span> myObj <span class=\"sf_code_syntax_keyword\">=<\/span> <span class=\"sf_code_syntax_keyword\">new<\/span> <span class=\"sf_code_syntax_keyword\">Object<\/span>()\r\nmyObj.someKey <span class=\"sf_code_syntax_keyword\">=<\/span> <span class=\"sf_code_syntax_string\">\"some value\"<\/span>\r\nmyObj.someOtherKey <span class=\"sf_code_syntax_keyword\">=<\/span> <span class=\"sf_code_syntax_number\">true<\/span>\r\nmyObj.key3 <span class=\"sf_code_syntax_keyword\">=<\/span> <span class=\"sf_code_syntax_number\">42<\/span><\/code><\/pre>\n<p><\/p>\n<p>The <code class='code-inline'>Object<\/code> prototype is the most basic prototype JavaScript has. It doesn\u2019t add any <i>data<\/i> properties, but it does add a small number of functions. Try making a plain object, then calling <code class='code-inline'>toString()<\/code> on it. The result isn\u2019t very helpful, but you do get a result, so that proves that the function exists.<\/p>\n<p><\/p>\n<p>Now we know that the squiggly brackets for objects, the square brackets for arrays, the <code class='code-inline'>function<\/code> keyword for functions, and the slashes for regular expressions are all just special syntaxes that make it more convenient to make objects with some specific prototypes. That means that, really, there are just two ways to make objects: <code class='code-inline'>new<\/code>, and one of those special syntaxes that just hides a <code class='code-inline'>new<\/code> under the hood*. <b>Any way of creating anything, unless it\u2019s a boolean, number, or string, is just creating an object under the hood. Or, in other words, anything that isn\u2019t a boolean, number, or string is an object.<\/b> As promised, we have now hopefully reconciled the two definitions of an object that we started with. Anything in JavaScript that isn\u2019t a boolean, number, or string is a collection of name-value pairs, aka an object. Some objects are plain, others are arrays, others are functions, and others are some other type of object &mdash; it all depends on the object\u2019s prototype.<\/p>\n<p><\/p>\n<p>(* There are technically two other ways to make an object. <code class='code-inline'>Object.create()<\/code> is a built-in function that creates an object in advanced ways. Also, when you use the square brackets or dot syntax a number, boolean, or string, as if it were an object, it gets temporarily converted to an object with prototype <code class='code-inline'>Number<\/code>, <code class='code-inline'>Boolean<\/code>, or <code class='code-inline'>String<\/code> respectively.)<\/p>\n<p><\/p>\n<p>I can now tell you the technical definition of a plain object: A plain object is an object with the prototype <code class='code-inline'>Object<\/code>. There are three ways to get one of those: the squiggly-brackets syntax we are used to, <code class='code-inline'>new Object()<\/code>, and a static function we haven\u2019t learned about called <code class='code-inline'>Object.create()<\/code> that lets you do some advanced stuff. But 99.99% of the time there\u2019s no reason not to use squiggly brackets, so a very easy definition that\u2019s <i>almost<\/i> always true is <b>plain objects are objects created using squiggly brackets<\/b>. <\/p>\n<p><\/p>\n<p>JavaScript programmers very often just say \u201cobject\u201d when we mean \u201cplain object\u201d. This came up in PBS 51 when you were reviewing the previous challenge. Bart said to make the fifth argument expect an object. You made it expect an array, then he said that was wrong because he wanted an object. But, as you pointed out, an array is an object! He said it was wrong because he wanted a <i>plain<\/i> object. Who is technically right depends on how you want to read the challenge description. Bart does mention earlier that it\u2019s going to be a plain object, but the sentence that actually tells you what to do just says to make \u201ca single optional object named <code class='code-inline'>opts<\/code>\u201d, which doesn\u2019t mention plain-ness. I encourage you to ask Bart often whether he means <i>any<\/i> object or specifically a <i>plain<\/i> object, until you build enough experience to figure it out from context. <\/p>\n<\/p><\/div>\n<p>        <script type=\"text\/javascript\">\n            (function() {<\/p>\n<p>    var doc_ols = document.getElementsByTagName(\"ol\");<\/p>\n<p>    for ( i=0; i<doc_ols.length; i++) {\n\n        var ol_start = doc_ols[i].getAttribute(\"start\") - 1;\n        doc_ols[i].setAttribute(\"style\", \"counter-reset:ol \" + ol_start + \";\");\n\n    }\n\n})();\n        <\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The following explanation is from an old friend of the show, Will (also known as @beiju). Unbeknownst to us, he&#8217;s been following along with Programming By Stealth all this time and just popped his head up for the first time in quite a few years. Will wrote the following in an email to Bart and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":13740,"parent":4374,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"jetpack_post_was_ever_published":false,"footnotes":""},"categories":[172,213],"tags":[616,2082,934,176,240,9],"class_list":["post-14802","page","type-page","status-publish","has-post-thumbnail","hentry","category-ccatp","category-programming-by-stealth","tag-javascript","tag-object-oriented-programming","tag-objects","tag-programming","tag-programming-by-stealth","tag-tutorials","post"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.podfeet.com\/blog\/wp-json\/wp\/v2\/pages\/14802","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.podfeet.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.podfeet.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.podfeet.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.podfeet.com\/blog\/wp-json\/wp\/v2\/comments?post=14802"}],"version-history":[{"count":7,"href":"https:\/\/www.podfeet.com\/blog\/wp-json\/wp\/v2\/pages\/14802\/revisions"}],"predecessor-version":[{"id":14829,"href":"https:\/\/www.podfeet.com\/blog\/wp-json\/wp\/v2\/pages\/14802\/revisions\/14829"}],"up":[{"embeddable":true,"href":"https:\/\/www.podfeet.com\/blog\/wp-json\/wp\/v2\/pages\/4374"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.podfeet.com\/blog\/wp-json\/wp\/v2\/media\/13740"}],"wp:attachment":[{"href":"https:\/\/www.podfeet.com\/blog\/wp-json\/wp\/v2\/media?parent=14802"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.podfeet.com\/blog\/wp-json\/wp\/v2\/categories?post=14802"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.podfeet.com\/blog\/wp-json\/wp\/v2\/tags?post=14802"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}