๐–๐ก๐š๐ญ ๐ฐ๐ข๐ฅ๐ฅ ๐›๐ž ๐ฅ๐จ๐ ๐ ๐ž๐ ๐ญ๐จ ๐ญ๐ก๐ž ๐œ๐จ๐ง๐ฌ๐จ๐ฅ๐ž?

 ๐–๐ก๐š๐ญ ๐ฐ๐ข๐ฅ๐ฅ ๐›๐ž ๐ฅ๐จ๐ ๐ ๐ž๐ ๐ญ๐จ ๐ญ๐ก๐ž ๐œ๐จ๐ง๐ฌ๐จ๐ฅ๐ž?


โ€‹
๐–๐ก๐š๐ญ ๐ฐ๐ข๐ฅ๐ฅ ๐›๐ž ๐ฅ๐จ๐ ๐ ๐ž๐ ๐ญ๐จ ๐ญ๐ก๐ž ๐œ๐จ๐ง๐ฌ๐จ๐ฅ๐ž?
โ€‹
Here is the answer & explanation of this question:
โ€‹
First, we have an object named โ€œincomeโ€ with three properties:
โ€‹
1. โ€œ๐ฌ๐ค๐ข๐ฅ๐ฅ๐ฌโ€, which is set to 108.
2. โ€œ๐ฆ๐จ๐ง๐ญ๐ก๐ฅ๐ฒโ€, which is a method that calculates the monthly income based on the โ€œ๐ฌ๐ค๐ข๐ฅ๐ฅ๐ฌโ€ value.
3. โ€œ๐ฒ๐ž๐š๐ซ๐ฅ๐ฒโ€, which is an arrow function meant to calculate the yearly income.
โ€‹
๐„๐ฑ๐ฉ๐ฅ๐š๐ง๐š๐ญ๐ข๐จ๐ง ๐จ๐Ÿ โ€œ๐ฆ๐จ๐ง๐ญ๐ก๐ฅ๐ฒ()โ€ ๐ฆ๐ž๐ญ๐ก๐จ๐:
โ€‹
1. โ€œ๐ฆ๐จ๐ง๐ญ๐ก๐ฅ๐ฒ()โ€ is a regular function. When you call โ€œ๐ข๐ง๐œ๐จ๐ฆ๐ž.๐ฆ๐จ๐ง๐ญ๐ก๐ฅ๐ฒ()โ€, this refers to the โ€œ๐ข๐ง๐œ๐จ๐ฆ๐žโ€ object.
2. โ€œ๐ญ๐ก๐ข๐ฌ.๐ฌ๐ค๐ข๐ฅ๐ฅ๐ฌโ€ inside the โ€œ๐ฆ๐จ๐ง๐ญ๐ก๐ฅ๐ฒ()โ€ method correctly refers to โ€œ๐ข๐ง๐œ๐จ๐ฆ๐ž.๐ฌ๐ค๐ข๐ฅ๐ฅ๐ฌโ€, which is 108.
3. So, โ€œ๐ญ๐ก๐ข๐ฌ.๐ฌ๐ค๐ข๐ฅ๐ฅ๐ฌ * ๐Ÿ๐ŸŽ๐Ÿ–โ€ becomes โ€œ๐Ÿ๐ŸŽ๐Ÿ– * ๐Ÿ๐ŸŽ๐Ÿ–โ€, which equals 11664.
4. Therefore, โ€œ๐ข๐ง๐œ๐จ๐ฆ๐ž.๐ฆ๐จ๐ง๐ญ๐ก๐ฅ๐ฒ()โ€ returns 11664.
โ€‹
๐„๐ฑ๐ฉ๐ฅ๐š๐ง๐š๐ญ๐ข๐จ๐ง ๐จ๐Ÿ โ€œ๐ฒ๐ž๐š๐ซ๐ฅ๐ฒโ€ ๐š๐ซ๐ซ๐จ๐ฐ ๐Ÿ๐ฎ๐ง๐œ๐ญ๐ข๐จ๐ง:
โ€‹
1. โ€œ๐ฒ๐ž๐š๐ซ๐ฅ๐ฒโ€ is defined as an arrow function.
2. Arrow functions do not have their own โ€œ๐ญ๐ก๐ข๐ฌโ€ context; they inherit โ€œ๐ญ๐ก๐ข๐ฌโ€ from the surrounding (lexical) context at the time they are defined.
3. In this case, โ€œ๐ญ๐ก๐ข๐ฌโ€ in โ€œyearlyโ€ refers to the global object (โ€œ๐ฐ๐ข๐ง๐๐จ๐ฐโ€ in browsers, โ€œ๐ ๐ฅ๐จ๐›๐š๐ฅโ€ in Node.js), not the โ€œ๐ข๐ง๐œ๐จ๐ฆ๐žโ€ object.
4. Since there is no โ€œ๐ฌ๐ค๐ข๐ฅ๐ฅ๐ฌโ€ property on the global object, โ€œ๐ญ๐ก๐ข๐ฌ.๐ฌ๐ค๐ข๐ฅ๐ฅ๐ฌโ€ is โ€œ๐ฎ๐ง๐๐ž๐Ÿ๐ข๐ง๐ž๐โ€.
5. As a result, โ€œ๐Ÿ–๐Ÿ–๐Ÿ– * ๐ญ๐ก๐ข๐ฌ.๐ฌ๐ค๐ข๐ฅ๐ฅ๐ฌโ€ becomes โ€œ๐Ÿ–๐Ÿ–๐Ÿ– * ๐ฎ๐ง๐๐ž๐Ÿ๐ข๐ง๐ž๐โ€, which is โ€œ๐๐š๐โ€ (Not a Number).
6. Therefore, โ€œ๐ข๐ง๐œ๐จ๐ฆ๐ž.๐ฒ๐ž๐š๐ซ๐ฅ๐ฒ()โ€ returns โ€œ๐๐š๐โ€.
โ€‹
๐“๐จ ๐ฌ๐ฎ๐ฆ๐ฆ๐š๐ซ๐ข๐ณ๐ž:
โ€‹
1. โ€œ๐ข๐ง๐œ๐จ๐ฆ๐ž.๐ฆ๐จ๐ง๐ญ๐ก๐ฅ๐ฒ()โ€ works as expected and returns 11664 because โ€œ๐ญ๐ก๐ข๐ฌโ€ correctly refers to the โ€œ๐ข๐ง๐œ๐จ๐ฆ๐žโ€ object.
2. โ€œ๐ข๐ง๐œ๐จ๐ฆ๐ž.๐ฒ๐ž๐š๐ซ๐ฅ๐ฒ()โ€ returns โ€œ๐๐š๐โ€ because โ€œ๐ญ๐ก๐ข๐ฌโ€ inside the arrow function does not refer to the โ€œ๐ข๐ง๐œ๐จ๐ฆ๐žโ€ object, leading to โ€œ๐ญ๐ก๐ข๐ฌ.๐ฌ๐ค๐ข๐ฅ๐ฅ๐ฌโ€ being โ€œ๐ฎ๐ง๐๐ž๐Ÿ๐ข๐ง๐ž๐โ€.
โ€‹
โ€‹
โ€‹
๐…๐จ๐ฅ๐ฅ๐จ๐ฐ ๐ญ๐ก๐ข๐ฌ ๐ฉ๐š๐ ๐ž ๐Ÿ๐จ๐ซ ๐ฆ๐จ๐ซ๐ž ๐œ๐จ๐ง๐ญ๐ž๐ง๐ญ ๐ฅ๐ข๐ค๐ž ๐ญ๐ก๐ข๐ฌ.

No comments:

Post a Comment

server laravel application

 asset_url = domain/public chmod -R 755 public/admin/ composer dump-autoload get the application from hostinger