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
Barry Cunningham
1 hour agoPRESIDENT TRUMP PRESSER | SUPREME COURT DECISION | DEMOCRATS RUNNING SCARED AND MORE NEWS!
1,923 watching -
48:20
The Kevin Trudeau Show Limitless
4 hours agoSILENT KILLERS in Your Life: Health Expert Dr. Pompa Exposes Heavy Metals, Plastics & Beauty Product
1381 -
1:03:59
Timcast
2 hours agoDemocrat ARRESTED In NYC For ASSAULTING ICE, Trump RAMPS UP Arrest Of Democrats
116K103 -
2:00:31
Steven Crowder
5 hours ago🔴Tucker Carlson Blasts Ted Cruz on Iran: What This Exchange Really Means
324K276 -
LIVE
LFA TV
17 hours agoLFA TV ALL DAY STREAM - WEDNESDAY 6/18/25
2,603 watching -
1:11:19
The Rubin Report
3 hours ago‘The View’s Sunny Hostin Gets Visibly Angry When Arnold Schwarzenegger Puts Her in Her Place
47.8K53 -
LIVE
Rebel News
1 hour agoCarney says US deal is close, CUPE rallies for Iran, Liberal MP calls out his party | Rebel Roundup
457 watching -
1:51:48
Side Scrollers Podcast
3 hours agoMarathon Delayed INDEFINITELY, Switch 2’s STOLEN, RIP Anne Burrell | Side Scrollers Live
8.67K2 -
25:42
IsaacButterfield
9 hours ago $0.17 earnedAmerica Is Broken
7.95K17 -
1:22:19
The Shannon Joy Show
4 hours ago🔥🔥False Flag Incoming? Concerns About Another Military Lockdown Under Trump Are Amplified As War Rhetoric Heats Up. With Special Guest Doc Malik🔥🔥
13.6K4