prototype Property

The functions in JavaScript are objects and they contain methods and properties. Inbuilt methods of object are like apply() and call() and some of the properties are length and constructor. There is another property of the function objects called prototype.

In the below example from the function foo() you can access its properties similar to another object.

function foo(a, b) {
    return a * b;

As soon as you define the function a property prototype gets created. Its initial value is an empty object.

typeof foo.prototype


It is similar to property created like below.

foo.prototype = {}

You can augment(add) properties and methods with empty object. They'll be used when you use foo() as a constructor.

Related Tutorial
Follow Us #
Contents +