Oh my ... there’s a lot to answer in such a short time ... But you have a long way to go in JavaScript, but you will like it ...
1) The designation of the object. You must google for JSON.
An object designation means that you can define data in a specific format related to JavaScript.
{} in the designation of objects means an object ... more specifically, it is already an instance of an object.
You can also write this in simple javascript, it will look like this:
new Object()
2) Functions are first class citizens.
Well, features are indeed a very valuable asset in the JS ecosystem. This means that you can do basically everything you imagine. This includes copying a reference to a function that "belongs" to another object.
{}. toString is a function. You usually call it by executing {} .toString ()
Instead, you simply copy the function reference in the variable. In this case, you "store" the function in the variable "toClass"
3) The prototype chain. You have to google, well, prototype circuit haha.
A prototype chain, for simple things, is like "class inheritance." So this means that if class A has a blah method and class B is a child of class A, it will also have a blah method.
In the JS world, the top of the prototype is "Object." And many features are already defined in the prototype. object. Enabling "toString"
4) The general problem of relativity ... aka this, challenge and application.
Since functions are first-class citizens, they can, in principle, exist, not even belonging to a specific instance of an object.
This means that you can choose in which context you want to enable the function.
By default, when calling functions that seem to be “attached” to an object, this object becomes this context of this function call:
{}.toString() // This executes toString in the context of {}
But, as I said, you can simply choose where the function actually executes. There are “call” and “apply” methods for this.
Our previous example can be translated into:
Object.prototype.toString.call({})
5) Global objects in your environment.
This is not a simple topic, because now JavaScript works not only in the browser, but also on the server ... NodeJS is a good example of this.
Assuming you run this in a browser ... there is a global object called window
You can call any function in a global object.
Thus, toString is equivalent to the .toString window , and the window is a descendant of Object, it will also get a method from Object.prototype.
Now your answer
getAge is not defined in Object.prototype, so you cannot call a non-existent function.