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();
-
19:55
The Rad Factory
14 hours ago $0.48 earnedCan I Fix My Fire Damaged F1 Car?
3.71K1 -
1:26:22
Dialogue works
2 days ago $0.20 earnedScott Ritter: Russia Just DEFIED the U.S.: We'll End the War on OUR Terms!
6656 -
LIVE
BEK TV
22 hours agoTrent Loos in the Morning - 8/01/2025
357 watching -
13:08
Dad Saves America
12 hours ago $0.86 earnedTeachers Unions Play Politics While Students Lag Behind - Poisoning of the American Mind: Pt 4
11.4K9 -
20:05
Preston Stewart
12 hours ago $1.59 earnedCrimea Raid to Chasiv Yar Fight
10.9K8 -
8:11
Millionaire Mentor
15 hours agoTulsi Gabbard and Leavitt DOUBLE-TEAM Kaitlan Collins in FIERY Exchange
8.87K5 -
46:02
Coin Stories with Natalie Brunell
1 day agoWhat They’re Hiding About the Economy | Natalie Brunell with Danielle DiMartino Booth
42K7 -
12:12
GritsGG
14 hours ago23 Warzone Wins in a Row! (Cypher AR)
84.1K3 -
2:12:07
Side Scrollers Podcast
21 hours agoCULTURE SHIFT CAUSES MELTDOWNS + MASSIVE CENSORSHIP EFFORTS RAMP UP | SIDE SCROLLERS LIVE
26.8K12 -
11:25
Nikko Ortiz
1 day agoMost Painful Fails
57.9K30