You can’t access the weight private variable outside of the closure in this way. Instead, you need to access it using the getter function getWeight(). If you wanna modify it, you should create a setter function that sets the private variable. If you try to modify the variable without a setter, this won’t affect the variable in the closure. Because the closure takes a copy of that variable, so it can’t be modified from outside the function.
So, your code should be as follows
function Bird() {
let weight = 15;
this.getWeight = function() {
return weight;
}
}
let bird = new Bird();
console.log(bird.getWeight())