Node.js Dot Notation as Namespace Mechanism

By Xah Lee. Date: . Last updated: .

In node.js, when you have a dot notation like


the x is used purely as a namespace, not as “data”.


const p = require('path');
const x = p.extname('xyz.html')
console.log ( x ); // .html

This is true for about all node.js objects.

This is interesting because the item before the dot is usually considered as a object that represent a piece of data in Object Oriented Programing languages. For example, in JavaScript:

" x ".trim()

Unix Pipe, Dot Notation, Postfix Notation