JavaScript Internals (521 Qs)•Part 2: Promises, Callbacks, Async & Strict Mode (54 - 103)
What is the difference between native, host and user objects
Native objects are objects that are part of the JavaScript language defined by the ECMAScript specification. For example, String, Math, RegExp, Object, Function etc core objects defined in the ECMAScript spec.
Host objects are objects provided by the browser or runtime environment (Node).
For example, window, XmlHttpRequest, DOM nodes etc are considered as host objects.
User objects are objects defined in the javascript code. For example, User objects created for profile information.
Practical Code Example
javascript
// 1. Native Objects: Defined by ECMAScript spec (Array, Object, Date, Math, RegExp)
const arr = new Array(1, 2, 3);
// 2. Host Objects: Supplied by browser/Node runtime environment (window, document, fetch)
console.log(window.location.hostname);
// 3. User Objects: Created in application code
class Developer {
constructor(name) { this.name = name; }
}
const dev = new Developer('Alex');