TypeScript Tutorial in Hindi #30 static keyword
Static Keyword
Why static keyword?
Advantage of static keyword?
How to use static property
How to use static functions
Example.
Interview Questions.
UseCase
use to define static property and methods.
Memory Efficiency
Utility Methods
Global Constants
static.ts
class Company{
static name:string="Google"
location="Noida"
static getName(){
return "gurgaon"
}
}
Math.random()
var c1= new Company();
// console.log(c1.name);
// console.log(Company.name);
console.log(Company.getName());
static.js
"use strict";
class Company {
static name = "Google";
location = "Noida";
static getName() {
return "gurgaon";
}
}
Math.random();
var c1 = new Company();
// console.log(c1.name);
// console.log(Company.name);
console.log(Company.getName());