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
GritsGG
19 hours ago36 Hour Marathon Stream! Most Wins in WORLD! 3704+!
2,047 watching -
15:10
Dr Disrespect
18 hours agoI FINALLY Beat Baby Steps
10.5K11 -
8:38
MattMorseTV
13 hours ago $6.32 earnedThis is CATASTROPHIC for the Dems.
16.4K12 -
19:54
Forrest Galante
2 days agoPrivate Tour Of America's Best Marine Animal Facility
73.5K9 -
2:59:11
Side Scrollers Podcast
19 hours agoDEI’s FINAL BOSS EXPOSED + Book Publisher REVERSES Cancel Attempt + More | Side Scrollers
54.2K19 -
23:00
The Pascal Show
10 hours ago $1.75 earnedCANDACE EXPOSES TEXTS! Candace Owens Shows Proof Charlie Kirk Was B*llied By Donors Before His Death
7.69K5 -
1:31:37
The HotSeat
14 hours agoBondi On The Hill + Equitable Grading? We Are Failing Our KIDS!
30.8K6 -
6:05
Spooky Grandpa's Scary Stories
1 month agoTHE HARVEST MAN (Halloween, Horror, Folklore, Supernatural, Paranormal)
9.01K7 -
LIVE
Lofi Girl
2 years agoSynthwave Radio 🌌 - beats to chill/game to
241 watching -
1:02:11
DeVory Darkins
13 hours ago $37.80 earnedDemocrats suffers ANNIHILATION during heated hearing with Bondi as Jack Smith bombshell drops
160K110