We can use the static keyword to enable the usage properties and methods in a class without needing to create an instance of it:
class TemperatureConverter { public static CelsiusToFahrenheit( celsiusTemperature: number ) { return (celsiusTemperature * 9 / 5) + 32; } public static FahrenheitToCelsius( fahrenheitTemperature: number ) { return (fahrenheitTemperature - 32) * 5 / 9; } }
As we can observe in the preceding code snippet, the TemperatureConverter class has two static methods named CelsiusToFahrenheit and FahrenheitToCelsius. We can invoke these methods without creating an instance of the TemperatureConverter class:
let fahrenheit = 100; let celsius = TemperatureConverter.FahrenheitToCelsius(fahrenheit); fahrenheit ...