Skip to content

Latest commit

 

History

History
62 lines (40 loc) · 1.86 KB

File metadata and controls

62 lines (40 loc) · 1.86 KB

Global Object function

JavaScript runtime has many global objects and functions. Global object function is a function in JavaScript which is called as Object

Let's see an example:

console.log(Object); //Global constructor function with name as Object

Above statement gives the definition of the Object function.

Prototype of the Object() function

console.log(Object.prototype); //Global constructor function with name as Object

Let's call this function

console.log(Object()); //Outputs: Empty object with __proto__ prperty

Object() gives an object which is empty and have proto property This object is inherited by all other objects in JavaScript

__proto__ property points to the prototype object of the constructor function i.e Object()

var obj = Object()
console.log(obj.__proto__); //Outputs: An object with some properties
console.log(a.__proto__ === Object.prototype) //true

Let's create an empty functiom

var a = function(){}
console.log(a.prototype)

Above image shows that a.prototype has two propertis

  1. constructor - which points to the function itself (console.log(a === a.prototype.constructor) // true)
  2. proto - which is inherited from Object()
console.log(a.prototype.__proto__ === Object().__proto__); //Output: true