I'm on the bracket and dot notation challenge in JS, I understand (more or less) how it works, but I can't with a little point:
Why I can't use Dot Notation whwn a property name is stored in a variable?
This is undefined:
var car = {
seats: "cloth",
engine: "V-6"
};
var s = "seats";
function show_seat_type(sts) {
window.alert(car.sts); // undefined
}
show_seat_type(s);
This is OK
var car = {
seats: "cloth",
engine: "V-6"
};
var s = "seats";
function show_seat_type(sts) {
window.alert(car[sts]); // works
}
show_seat_type(s);
But why? Thanks guys.