Javascript Object Oriented Concept:

  • A JavaScript object is, in that sense, a collection of named properties and methods .
  • Objects are a way to categorize behavior and data, making large amounts of code easier to design and think about.
  • An object can be stored in a variable, and the properties and methods accessed using the dot syntax.
  • Variables can hold objects, and creating an object is done using a special syntax signified by braces:

Example of Object in javascript:

  1. var per= {
  2. name: “sha”,
  3. age: 32,
  4. getage: function () { alert(“hello world”);
  5. }

In order to access items , we use dot operator like
  • per.age
  • per.getage();
  • You can also assign values
  • per.age
Creating an empty object
  • var obj={};
  •{ alert(“hello”);};

Prototypal inheritance:

JavaScript uses prototypal inheritance. This means that, when an object inherits from another, the parent object is known as the child’s prototype.

Javascript Closure:
  • closureis a function that returns a function.
  • The function that is returned (the innerfunction)
  • is created inside the called function (the outer) so – due to the

Example :

  1. var sub= function (a) {
  2. return function (b) { return a -b; }; };
  3. var addFive = sub(4);
  4. alert(addFive(10))