foo.bar =1 so why it doesnt return a number.
Why foo.bar not return a number
@joshiajay311 what you are doing here is passing an object in function and calling it,
(function(foo){ return typeof foo.bar; })({ foo: { bar: 1 } });
here
{ foo:{ bar: 1 }}
is the foo parameter in function, thus foo has a property foo which again has a property bar thus first foo doesn’t have bar property, hence undefined
Try running this, and check the output
(function(foo){ return typeof foo.foo.bar; })({ foo: { bar: 1 } });
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.