Objects and Prototypes in JavaScript

AhmedAmeer
2 min readMar 5, 2021

Objects

  • Objects are essentially a collection of multiple values .you can have values and variables which are primitives like a Number ,string , Boolean or it can be something like an object and you can add a lot of other values in an object like an object itself, you can have an array and you can have a function
  • JavaScript is not Class based so there is no blueprints that every objects need to adhere to. we can create any property on any object whenever we want and there is no datatype restrictions

There are many types of methods to create object

Method 1

Method 2

Method 3

Creating an object through function

Method 4

Creating an object through constructor

Prototypes

  • A prototype is an existing inbuilt functionality in JavaScript. Whenever we create a JavaScript function, JavaScript adds a prototype property to that function. A prototype is an object, The variables and methods available in the prototype object can be accessible, modifiable, and even can create new variables and functions.

Example 1

Creating a function in an already created object using prototype object

  • Prototype is a base class for all the objects, and it helps us to achieve the inheritance.

Example 2

Inheritance Concept

--

--

AhmedAmeer
AhmedAmeer

Written by AhmedAmeer

I’m an undergraduate student from SLIIT

No responses yet