Static in ECMAScript

Create new Javascript file named index.js. This file contains code demo as below:

class Math {

    static square(a) {
        return a * a;
    }

    static cube(a) {
        return a * a * a;
    }

}

console.log('square: ' + Math.square(2));
console.log('cube: ' + Math.cube(3));




Use node index.js statement run code demo

square: 4
cube: 27