Static Keyword in JavaScript | #39

preview_player
Показать описание
Static Keyword in JavaScript | #39

Courses:

HTML:

CSS:

Other videos

► How to Make Animated Portfolio Website Using HTML CSS & JS - Light & Dark Mode Website Tutorial:

► Responsive Personal Portfolio Website using HTML & CSS - How to Make a Website:

► Animated Portfolio Website Template in HTML CSS | Animated Personal Website - Responsive Design:

► How To Make A Website Using HTML CSS Bootstrap - Real Estate Website - Bootstrap Website Design:

► Responsive Ecommerce Website:

►CSS Button Hover Effect:

►CSS Loading Animation:

►Video Background Landing Page:

►Working JavaScript Clock:

►CSS Loading Animation Effects:

Instagram:
Рекомендации по теме
Комментарии
Автор

//EXP1
class MathOperations {
//static method
static add(x, y) {
console.log(`X + Y = ${x + y}`);
}

static multiply(x, y) {
console.log(`X * Y = ${x * y}`);
}

divide(x, y) {
console.log(`X / Y = ${x / y}`);
}
}

MathOperations.add(5, 3); //access static method
MathOperations.multiply(3, 9);

const object = new MathOperations(); //access normal method
object.divide(8, 2);


//EXP2
class Circle {
// Static properties
static PI = 3.14159;
static numberOfCircles = 0;

constructor(radius) {
this.radius = radius;
Circle.numberOfCircles++;
}

// calculate the area
calculateArea() {
return Circle.PI * this.radius ** 2;
}

// calculate total number of circles
static getTotalCircles() {
return Circle.numberOfCircles;
}
}

// Creating objects
const circle1 = new Circle(3);
const circle2 = new Circle(5);

// Accessing instance methods
console.log("Area of circle1:", circle1.calculateArea());
console.log("Area of circle2:", circle2.calculateArea());

// Accessing the static method
console.log("Total number of circles:", Circle.getTotalCircles());

webcontent
Автор

This cleared my static keyword logic
I also understood what role constructer plays

nirajs.golhar