Premium Only Content
 
			Learn JavaScript STATIC keyword in 8 minutes! ⚡
// static = keyword that defines properties or methods that belong
// to a class itself rather than the objects created
// from that class (class owns anything static, not the objects)
// ----------- EXAMPLE 1 -----------
class MathUtil{
static PI = 3.14159;
static getDiameter(radius){
return radius * 2;
}
static getCircumference(radius){
return 2 * this.PI * radius;
}
static getArea(radius){
return this.PI * radius * radius;
}
}
console.log(MathUtil.PI);
console.log(MathUtil.getDiameter(10));
console.log(MathUtil.getCircumference(10));
console.log(MathUtil.getArea(10));
// ----------- EXAMPLE 2 -----------
class User{
static userCount = 0;
constructor(username){
this.username = username;
User.userCount++;
}
static getUserCount(){
console.log(`There are ${User.userCount} users online`);
}
sayHello(){
console.log(`Hello, my username is ${this.username}`);
}
}
const user1 = new User("Spongebob");
const user2 = new User("Patrick");
const user3 = new User("Sandy");
user1.sayHello();
user2.sayHello();
user3.sayHello();
User.getUserCount();
- 	
				 LIVE LIVEDLDAfterDark3 hours agoDon't Worry - Things Will Get SO Much Worse! Sometimes It Be Like That191 watching
- 	
				 25:41 25:41Robbi On The Record9 hours agoThe Billion-Dollar Lie Behind OnlyFans “Empowerment” (Her Testimony Will Shock You) | part II1453
- 	
				 12:22 12:22Cash Jordan53 minutes ago"CHICAGO MOB" Fights Back... "ZERO MERCY" Marines DEFY Judge, SMASH ILLEGALS233
- 	
				 46:58 46:58Brad Owen Poker12 hours agoI Make QUAD ACES!!! BIGGEST Bounty Of My Life! Turning $0 Into $10,000+! Must See! Poker Vlog Ep 323321
- 	
				 2:52:28 2:52:28TimcastIRL4 hours agoSTATE OF EMERGENCY Declared Over Food Stamp CRISIS, Judge Says Trump MUST FUND SNAP | Timcast IRL190K108
- 	
				 DVR DVRTundra Tactical10 hours ago $14.20 earned🚨Gun News and Game Night🚨 ATF Form 1 Changes, BRN-180 Gen 3 Issues??, and Battlefield 6 Tonight!21.4K
- 	
				 1:45:13 1:45:13Glenn Greenwald7 hours agoJD Vance Confronted at Turning Point about Israel and Massie; Stephen Miller’s Wife Screams “Racist” and Threatens Cenk Uygur with Deportation; Rio's Police Massacre: 120 Dead | SYSTEM UPDATE #54098.3K101
- 	
				 LIVE LIVESpartakusLIVE4 hours agoSpart Flintstone brings PREHISTORIC DOMINION to REDSEC286 watching
- 	
				 1:05:02 1:05:02BonginoReport7 hours agoKamala CALLED OUT for “World Class” Deflection - Nightly Scroll w/ Hayley Caronia (Ep.167)118K69
- 	
				 54:36 54:36MattMorseTV5 hours ago $0.41 earned🔴The Democrats just SEALED their FATE.🔴52.4K93