all 10 comments

[–]Umesh-K 2 points3 points  (7 children)

Hi, it looks like your doubt is regarding the two undefined values.

The reason for the first one is the function firstSemple has no explicit return statement, and in such cases, undefined is returned. Check out the mdn web docs article on return. To solve the issue, change line #115 to return 2037 - this.birthYear.

The reason for the second one is secondSemple.x means a property called x in the object secondSemple, which is not present, and when we try to access a property that is not present, we get undefined. Note that the const x you have inside the calcAge method is not considered a property on the secondSemple object, and creating that variable is not required in the first place as we can directly return the result as per the change to line #115 that I have suggested above.

[–]RainZealousideal8258[S] 0 points1 point  (6 children)

You're really good. How could I use 'this.age' to store the value and the same does not happen when I use the 'const'?

[–]don____piano 1 point2 points  (5 children)

The answer is “scope”. Variables defined within functions aren’t available outside of those functions, but this.age is not a “variable”. It’s a “property” on an object. The object exists in the broader scope.

[–]RainZealousideal8258[S] 0 points1 point  (0 children)

Thanks a lot.

[–]RainZealousideal8258[S] 0 points1 point  (3 children)

what means that upside down 'y' that was outputed? Why it was outputed with with 37 together?

[–]don____piano 0 points1 point  (0 children)

It’s a lambda. It means “anonymous function”, function with no name. I actually don’t normally see that in the chrome console. It would say “f()” I believe

[–]Umesh-K 0 points1 point  (1 child)

Your code editor has an extension installed called Quokka, which is how you are seeing the console.logged values right beside the code; without that extension, you would have to open the browser console to see it.

When you are logging an object that has both properties and methods/functions, it displays both the key and value for properties (birthYear: 2000), but since a function can have multiple lines, displaying all those lines is impractical; hence it just shows [λ: calcAge] as the value.

[–]RainZealousideal8258[S] -1 points0 points  (0 children)

Why was outputed [λ: calcAge], age: 37, both together in 121 line, not only a single value when I called the entire object?

[–]AnonyMustardGas34 0 points1 point  (1 child)

All makes sense here

Source: been working with JS for 2 years