Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome Console Object Properties Shown with Angle and Square Brackets

When listing properties of an object in the Chrome console, I stumbled upon notations I had never seen before. Indeed, some properties were outlined with <angle-brackets-properties> and the [[double-square-brackets-properties]] notations. Could anyone shed some light on:

  • What these notations are for
  • What are the implications in terms of behaviour/modifiers of these properties (enumerable, writable, configurable, etc)
  • Whether this can be reproduced by pure Javascript operations, or if this is can only be achieved through native C++ objects
  • When this was introduced (ECMAScript spec)

You will find an example below: enter image description here

like image 338
Philippe Hebert Avatar asked Feb 14 '16 15:02

Philippe Hebert


People also ask

What is the difference between accessing an object with dot vs with [] in JavaScript?

The dot notation is used mostly as it is easier to read and comprehend and also less verbose. The main difference between dot notation and bracket notation is that the bracket notation allows us to access object properties using variable.

What are the two types of notations does object property have?

There are two ways to access properties: dot notation and bracket notation.

What do square brackets mean in JavaScript?

The [] operator converts the expression inside the square brackets to a string. For instance, if it is a numeric value, JavaScript converts it to a string and then uses that string as the property name, similar to the square bracket notation of objects to access their properties.

How do I show objects in console?

Answer: Use console. log() or JSON. stringify() Method You can use the console. log() method, if you simply wants to know what's inside an object for debugging purpose. This method will print the object in browser console.


1 Answers

Most of what you're asking is answered here. Just like that answer I'll go ahead and quote the spec:

They are defined by this specification purely for expository purposes. An implementation of ECMAScript must behave as if it produced and operated upon internal properties in the manner described here. The names of internal properties are enclosed in double square brackets [[ ]]. When an algorithm uses an internal property of an object and the object does not implement the indicated internal property, a TypeError exception is thrown.

like image 142
PEsteves Avatar answered Oct 22 '22 06:10

PEsteves