Skip to content
Related Articles

Related Articles

What is the difference between Host objects and Native objects ?

View Discussion
Improve Article
Save Article
  • Last Updated : 01 Aug, 2022
View Discussion
Improve Article
Save Article

In this article, we will learn about what are Host objects and Native objects, and their differences.

JavaScript objects are broadly classified into 2 categories – native javascript objects and host javascript objects. 

Native objects: Native javascript objects are standard javascript objects which are provided by javascript itself. They are also known as built-in objects, pre-defined objects, or global objects. These objects work in the same fashion and are available to all users, irrespective of the machine and the environment. Their functionalities do not change with the change in the machine or environment and can be used as both, constructors (like String(), Array(), Object()) and primitive values (like true, 999). 

For example:

  • String()
  • Number()
  • true

Example:

Javascript




<script>
    console.log(new Date())
    console.log(new String("Hello World"))
    console.log(new Number(123))
</script>

Output:

 

Host objects: Host javascript objects are environment-specific javascript objects, and may vary as per the environment of the machine in which the javascript is being used. Objects provided by one environment, may or may not be present in another environment. For example, most browsers provide window objects or navigator objects, but these objects are not present in the server running node.js. However, some objects like consoles are provided by both, the browsers and the node.js servers. Therefore, we can say that the host objects are host specific and may differ from one host (environment) to other.

For example:

  • window
  • NodeList
  • console

Example:

Javascript




<script>
    console.log(window)
    console.log(console)
    console.log(NodeList)
</script>

Output:

 

Difference between Native objects and Host objects:

Native Objects

Host Objects

These are standard global javascript objects which are the same and provided by javascript itself.These are the host (environment) specific javascript objects and differ from one environment to another.
These are available to all users globally.The objects offered by one environment may not be present in the other environment
Example: String(), Array(), Number(), false, “Hello World”Example: window, console, navigator, NodeList

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!