This question tests your understanding of this
inside an arrow function. Market Capitalization or "Market Cap" of a company is total market value of its outstanding shares. A company's Market Cap is calculated by multiplying company's current stock price by its outstanding shares. We have 2 objects IBM and MSFT representing stocks of IBM (International Business Machines) and Microsoft. IBM and MSFT objects contain the stock price and shares outstanding (in Millions):
let IBM = { price: 140.0,
sharesOutstanding: 1000 // Shares in Millions
};
let MSFT = { price: 125.0,
sharesOutstanding: 8000 // Shares in Millions
};
A function createMarketCapCalculator returns a Market Cap calculator arrow function for a stock object when invoked through call (or apply):
// Returns a market cap calculator
function createMarketCapCalculator() {
// Calculates Market Cap in Millions
return () => this.price * this.sharesOutstanding;
}
We create a Market Cap calculator for MSFT:
// Create a Market Cap Calculator for MSFT
let calcMarketCap = createMarketCapCalculator.call(MSFT);
But invoke that calculator on IBM through call:
// Invoke the MSFT Market Cap Calculator through 'call' for IBM
console.log(calcMarketCap.call(IBM));
What would be the output?