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();
-
2:31:01
The Connect: With Johnny Mitchell
1 day ago $34.65 earned"It's About To Get Worse"- CIA Agent Andrew Bustamante Explains Why It's Time To Leave America
37.7K71 -
16:21
The Pascal Show
1 day ago $1.20 earned'THE FEDS MADE THIS UP!' Candace Owens Drops BOMBSHELL Pushing Back On Details In Charlie Kirk Case
3.53K5 -
LIVE
Lofi Girl
2 years agoSynthwave Radio 🌌 - beats to chill/game to
273 watching -
25:39
DeVory Darkins
12 hours ago $20.02 earnedMass shooting erupts in Michigan as bombshell study shows left wing political violence skyrocketed
34.7K107 -
5:55:33
MattMorseTV
10 hours ago $123.95 earned🔴Portland ANTIFA vs. ICE.🔴
161K323 -
3:13:00
Badlands Media
1 day agoThe Narrative Ep. 40: Acceleratia.
70.9K25 -
6:57:01
SpartakusLIVE
9 hours ago#1 Solo Spartan Sunday || TOXIC Comms, TACTICAL Wins, ENDLESS Content
61K5 -
49:45
Sarah Westall
8 hours agoComedians take Center Stage as World goes Nuts w/ Jimmy Dore
43.6K20 -
3:26:14
IsaiahLCarter
16 hours ago $11.68 earnedAntifa Gets WRECKED. || APOSTATE RADIO 030 (Guests: Joel W. Berry, Josie the Redheaded Libertarian)
52.2K1 -
4:44:18
CassaiyanGaming
7 hours agoArena Breakout: Infinite Dawg
32.4K2