- The functions themselves are objects but they are callable, they are made from ‘Function’ Prototype.
- The function will have both the properties proto and Prototype, while object will have only proto. Think as proto on any object gives the blueprint of function/prototype it is created from. While prototype is property of function itself and is blueprint of the same.
Method creation via constructor vs prototype
- You can create method using prototype of using constructor approach. //Refer the example - 5
- Prototype way of adding properties/method is faster compared to construcor approach while constructor approach has access to private variable which prototype way does not.
Null and Undefined - Don’t remember no issue.
- string, number, bigInt, boolean, symbol have equivalent wrapper String, Number, BigInt, Boolean, Symbol.
- Primitive type are immutable. A new memory gets allocated when there is a change in value.
- null and undefined are only one which do not have object wrap.
- null is an object and is global. It points to a location.
- undefined is whenever a variable is not defined.
Nan - Don’t remember no issue.
Special Type of Number which comes when compiler doesn’t like numeric operation or you can say kind of exception.
Object Oriented Concepts
Making thing private.
Use closure to make thing private, they will not be visible to outside world and accessed normally using public method. Closure extends the scrope of object/variables even thought there parent reference no more exists. Here, The RetainExample call was over at the line 6, ‘a’ might have created and destroyed, not true since a function returned from outer function, the inner function lives forever with outer functions inner soul(variable/object - lexical scope).
There are mainly two ways you can inherit property of other function.
Using Constructor Call.
Using Object.create() Method
You can copy the object using create, it can copy prototype as well as in the end prototype property is an object.