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();
-
1:09:36
Sean Unpaved
3 hours agoBrian Kelly's Boot From LSU, NFL Week 8 Snoozefest, & CFB's Week 9 Upset Rodeo
9.56K1 -
LIVE
Jeff Ahern
35 minutes agoMonday Madness with Jeff Ahern
191 watching -
1:03:58
Timcast
3 hours agoTrump DEPLOYS Election Monitors To Blue States, Democrats SCREAM RIGGED ELECTION
155K120 -
2:07:27
Steven Crowder
5 hours agoWho Belongs: What the Future of the American Right Wing Looks Like
354K242 -
1:29:28
NAG Podcast
21 hours agoSay Something Beyond W/MikeMac: DARKSIDE - Ep.11
5.01K2 -
35:24
The Rubin Report
4 hours ago'Real Time' Crowd Goes Quiet as Bill Maher & Democrat Have a Tense Exchange About Zohran Mamdani
97K44 -
1:21:33
Rebel News
2 hours agoTrump says he can play dirty, Canada-US trade talks off, BC to launch anti-tariff ad | Rebel Roundup
14.9K9 -
2:26:58
Nikko Ortiz
4 hours agoValid Crashout's... |Rumble Live
13.8K3 -
LIVE
LFA TV
18 hours agoLIVE & BREAKING NEWS! | MONDAY 10/27/25
2,037 watching -
LIVE
StoneMountain64
2 hours agoBattlefield 6 Season 1 TOMORROW. Battle Royale? New Map + New Weapons!
109 watching