OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

What is the arr; syntax doing behind the scenes?

  • Thread starter Thread starter JSP
  • Start date Start date
J

JSP

Guest
This may be completely stupid but given I type this into my browser console:

Code:
var arr = [];
arr.item = 'val';
console.log( arr );
arr;

What is the arr; syntax doing behind the scenes? I'm assuming console.log( arr ); is iterating all the properties of the arr object but what is arr; doing? Also does [] tell me I'm dealing with an object of type array and {} tells me I'm dealing with an object of type object literal? So [ item: 'val' ] is an object with a prototype of array and { item: 'val' } is an object of prototype object literal?

Edit: Another way to ask this might be why are console.log and arr; different?

<p>This may be completely stupid but given I type this into my browser console:</p>

<pre><code>var arr = [];
arr.item = 'val';
console.log( arr );
arr;
</code></pre>

<p>What is the <code>arr;</code> syntax doing behind the scenes? I'm assuming <code>console.log( arr );</code> is iterating all the properties of the <code>arr</code> object but what is <code>arr;</code> doing? Also does <code>[]</code> tell me I'm dealing with an object of type array and <code>{}</code> tells me I'm dealing with an object of type object literal? So <code>[ item: 'val' ]</code> is an object with a prototype of array and <code>{ item: 'val' }</code> is an object of prototype object literal?</p>

<p>Edit: Another way to ask this might be why are <code>console.log</code> and <code>arr;</code> different?</p>
 

Latest posts

Top