My code is as follows:
class Rectangle {
constructor(height, length) {
this.height = height;
this.length = length;
}
area() {
return this.height * this.length;
}
}
const square = new Rectangle(10, 10);
console.log(square);
console.log(square.area());
However, my console is showing the following:
I'm trying to understand a few things.
- Why is the console saying
square
is undefined? - Why doesn't the console denote the class of
square
in the log, demoting it to a genericObject
rather than aRectangle
? - What processes can I adopt in my workflow to help me answer these questions before asking Stack Overflow?
I've checked my Firefox version and reviewed this on Safari as well, and the problem is the same. Initially, I was using a separate .js file to define a more complicated class, but after more and more simplification, I realized that even this basic case isn't working for me.
I've also noticed that other posts are about the reverse problem: something showing up in console but not in code.