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
LFA TV
12 hours agoLIVE & BREAKING NEWS! | WEDNESDAY 12/17/25
2,144 watching -
1:33:59
Game On!
18 hours ago $1.53 earnedBIGGEST 2025 College Football Playoff 1st Round BETS NOW!
21.6K2 -
1:04:39
Crypto Power Hour
11 hours ago $4.69 earnedState of Early Stage Crypto Investor Rob Good
39.6K8 -
1:24:24
LIVE WITH CHRIS'WORLD
18 hours agoTHE WAKE UP CALL - 12/17/2025 - Episode 27
20.9K -
27:51
ThinkStory
19 hours agoIT: WELCOME TO DERRY Season 1 Ending Explained!
26.9K -
5:29
Gamazda
13 hours ago $1.82 earnedMetallica - Nothing Else Matters (Live Piano in a Church)
19.2K7 -
2:50:56
The Confessionals
21 hours agoHe Killed a Monster (Then They Told Him to Stay Silent)
22.9K9 -
41:42
Brad Owen Poker
16 hours ago $0.78 earnedMy BIGGEST WIN EVER!! $50,000+ In DREAM Session!! Must See! BEST I’ve Ever Run! Poker Vlog Ep 360
15.6K1 -
17:53
The Illusion of Consensus
20 hours ago $1.10 earnedWhat Women REALLY Want in Public (It’s Not What You Think) | Geoffrey Miller
17.6K7 -
1:32:16
Uncommon Sense In Current Times
18 hours ago $0.81 earnedPolygyny Debate: The Biblical Case For and Against Plural Marriage | Uncommon Sense
16.6K1