Class Static Method in JavaScript
Level 4167 keystrokes
Static methods are called on the class itself, not on instances of the class.
JavaScript code
// Define a utility class with static methods1class MathUtils { // static keyword makes this a class method2 static add(a, b) { // Return the sum of two numbers3 return a + b;4 } // Another static method for multiplication5 static multiply(a, b) { // Return the product of two numbers6 return a * b;7 }8}// Call static method directly on the class9console.log(MathUtils.add(5, 3));// Call multiply static method10console.log(MathUtils.multiply(4, 2));Output
8 8
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this JavaScript code and how often they appear.
(× 6)× 6,× 4;× 4.× 4{× 3}× 3*× 1+× 1