Introduction
JavaScript is a language of the Web. This series of articles will talk about my observations learned during my decade of software development experience with JavaScript. What mistakes a developer generally makes and what differences they should be aware of.
In part 1, we learned about Data Types and touched on Objects. But part 2 will focus in detail on Objects. You can go through Part 1 from here,
Voice of a Developer: JavaScript Data Types.
Ans
Yes, let’s go back in C / C++ days where we have a concept of pointers,
ex
int x=49;
Q: Can you use save as a reference in Javascript like we have in other programming languages?
int *ptr;
ptr = &x;
This means that address of x is stored in ptr.

printf(“%d”, x); // 50
Ex
> var person = {name: "Sumit"};
Similarly, in Javascript the primitive data is saved-as-value. On the contrary, the save-as-reference mechanism is there for objects,
> var anotherPerson = person;
> person.name = "Ravi";
> console.log(anotherPerson.name); // Ravi
> console.log(person.name); // Ravi
The variable is a reference, not a value
The own properties are properties that were defined on the object, while the inherited properties were inherited from the object’s Prototype object.
We learned about own properties in part 1, ex- person.name // own property
Prototypal inheritance – Inherited property
In most OOPS based languages, classes inherit from classes. In Javascript, it’s prototype-based. Objects inherit from Objects. And, we know an object is a prototype of classes. Therefore, it’s the prototypical based inheritance
Ans: Use the property called __proto__
Ex
> var automobile = {engine: true};
Object Own and Inherited Properties
Q: How do we implement prototypal inheritance?
> var car = {tyres: 4};
Now, we know the car is a type of automobile, so we could inherit from the automobile.
> car.__proto__ = automobile; //inheritance
> car.engine; // true
Hence, there is CAR => Automobile (car is an automobile)

|
Enumerable
|
Non-Enumerable
|
|
Own properties are enumerable. This means you can iterate over these
|
Inherited properties are non-enumerable. These are hidden unless asked specifically
|
|
Ex- car.tyres
|
Ex car.engine
|
|
Object.keys (car) //tyres;
|
|
|
car.propertyIsEnumerable("tyres"); //true
|
car.hasOwnProperty("engine"); //false
|
|
car.hasOwnProperty("tyres"); // true
|
car.propertyIsEnumerable("engine"); //false
|
Q: Is __proto__ the only way to prototypal inheritance?
var car = Object.create(automobile);
Now, you could see car.engine is available
Ans: Yes, you could use the below pattern to validate,
ex
> "engine" in car; //true

Q: Is there any other way to check the property in an object?
> "valueOf" in {}; //true
Read more articles on JavaScript
Guest UserPosted May 14, 2016, 10:10 AM
Thanks Amit, Rajit, Debasis & others...
Rajib Das GuptaPosted May 14, 2016, 9:53 AM
Nice concept on inheritance.
Amit DavePosted May 3, 2016, 6:56 AM
Nice article!
RakeshPosted Apr 29, 2016, 3:05 PM
Good one sir
Debasis SahaPosted Apr 24, 2016, 1:09 PM
Good one..
Kuppurasu NagarajPosted Apr 24, 2016, 12:38 PM
Nice Sharing..
Rahul Kumar SaxenaPosted Apr 24, 2016, 12:15 PM
Good Show
Vignesh ManiPosted Apr 24, 2016, 9:46 AM
Nice