Hi,
I have a small question in javascript. Here is a declaration:
function answerToLifeUniverseAndEverything()
{
return 42;
}
var myLife = answerToLifeUniverseAndEverything();
If I do console.log(myLife)
It'll print 42, as I am just invoking the same instance of function resulting in 42 as the answer. (Basic rule on javascripts that only references of objects are passed and not the object)
Now on the other hand if I do
var myLife = new answerToLifeUniverseAndEverything();
Then I can't invoke the function; instead myLife becomes just an object? I understand that this is a new copy of the same function object and not a reference; but why can't I invoke the method?
Can you please clarify the basic fundamental I am missing here?
Cheers