Prototypes

Understand JavaScript prototypes

AdvancedTopic: Advanced JS
Back

JavaScript Prototypes Program

This program helps you to learn the fundamental structure and syntax of JavaScript programming.

Try This Code
function Person(name) { this.name = name; }
Person.prototype.greet = function() { return 'Hello, ' + this.name; };
const person = new Person('John');
console.log(person.greet());
Output
Hello, John

Understanding Prototypes

Prototypes enable object inheritance.

Note: To write and run JavaScript programs, you need to set up the local environment on your computer. Refer to the complete article Setting up JavaScript Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your JavaScript programs.

Table of Contents