Trying to create a class in JS with the attribute weight in the following code:
function Foo() {
var weight = 10;
console.log(weight);
}
When I instantiate it with var bar = new Foo();
, 10
is logged to the console.
When I later call console.log(bar.weight);
, undefined
is logged to the console. Why is that? I was under the impression that the attributes declared within a JS class were public by default?