Reputation: 39
I have read in this post (Difference between Node object and Element object?) that "A node is the generic name for any type of object in the DOM hierarchy". So now I'm wondering: are there any objects in JavaScript that aren't nodes? Can you give examples?
Upvotes: 0
Views: 547
Reputation: 48610
The Node
interface is used to represent DOM objects in the browser. All Node
implementations are an Object
, but not all Object
types have browser DOM interfaces backing them.
There is a distinction between standard built-in objects and web interface objects.
Web APIs are typically used with JavaScript, although this doesn't always have to be the case.
For more information about the distinction between the DOM and core JavaScript, see JavaScript technologies overview.
For example, the JavaScript in Node.js differs slightly from browser JavaScript, because the JavaScript in node runs headless and does not rely on a browser to execute. Most of the web-specific interfaces do not exist in the standard Node.js library. For more information, see: Differences between Node.js and the Browser
Upvotes: 1
Reputation: 370729
Lots and lots of things in JavaScript are objects. For example, the following is an object:
const obj = {};
As are many others, like the window
, the global Array object, and so on.
Nodes are a very specific type of object. Only a relatively small proportion of objects developers use are node objects. Nodes are only found in a front-end environment when working with the DOM, like the following:
const span = document.querySelector('span');
console.log(span.textContent);
<span>foo</span>
Upvotes: 3