Skip to content

JavaScript Dot notation | Property accessors

  • by

JavaScript Dot notation is Property accessors that provide access to an object’s properties. When working with dot notation, property identities can only be alphanumeric (and _ and $). Properties can’t start with a number.

object.property_name;

JavaScript Dot notation Example

Simple example code access properties on an object by specifying the name of the object, followed by a dot (period) followed by the property name.

<!DOCTYPE html>
<html>
<body>

  <script>
   let obj = {
    cat: 'meow',
    dog: 'woof'
  };

  let sound = obj.dog;

  console.log(sound);
</script>

</body>
</html>

Output:

JavaScript Dot notation

Dot notation is much easier to read than bracket notation and is therefore used more often.

const object = {};

object.$1 = 'foo';
console.log(object.$1);  // 'foo'

object.1 = 'bar';        // SyntaxError
console.log(object.1);   // SyntaxError

Do comment if you have any doubts or suggestions on this JS dot notation.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *