20250318
1.When is a JavaScript arrow function needed?
2. Other ways to create objects in JavaScript
3.
0)
1)
function Person(weight, height) {
this.weight = weight;
this.height = height;
}
const josue1 = new Person(70, 1.75);
const josue2 = new Person(80, 1.80);
2)
const personPrototype = {
calculateBMI: function() {
return this.weight / (this.height * this.height);
}
};
const josue1 = Object.create(personPrototype);
josue1.weight = 70;
josue1.height = 1.75;
3)
class Person {
constructor(weight, height) {
this.weight = weight;
this.height = height;
}
}
const josue1 = new Person(70, 1.75);
const josue2 = new Person(80, 1.80);
public class Student {
int weight;
double height;
public Student(int weight, double height) {
this.weight = weight;
this.height = height;
}
}
Student josue1 = new Student(70, 1.75);
Student josue2 = new Student(80, 1.80);