crop_rotate
Run
<!DOCTYPE html> <html> <body> <h2>JavaScript Classes are written in "strict mode"</h2> <p>In a JavaScript Class you cannot use variable without declaring it.</p> <p id="demo"></p> <script> class Car { constructor(name, year) { this.name = name; this.year = year; } age() { // date = new Date(); // This will not work let date = new Date(); // This will work return date.getFullYear() - this.year; } } myCar = new Car("Ford", 2014); document.getElementById("demo").innerHTML = "My car is " + myCar.age() + " years old."; </script> </body> </html>
PCFET0NUWVBFIGh0bWw+DQo8aHRtbD4NCjxib2R5Pg0KDQo8aDI+SmF2YVNjcmlwdCBDbGFzc2VzIGFyZSB3cml0dGVuIGluICJzdHJpY3QgbW9kZSI8L2gyPg0KDQo8cD5JbiBhIEphdmFTY3JpcHQgQ2xhc3MgeW91IGNhbm5vdCB1c2UgdmFyaWFibGUgd2l0aG91dCBkZWNsYXJpbmcgaXQuPC9wPg0KDQo8cCBpZD0iZGVtbyI+PC9wPg0KDQo8c2NyaXB0Pg0KY2xhc3MgQ2FyIHsNCiAgY29uc3RydWN0b3IobmFtZSwgeWVhcikgew0KICAgIHRoaXMubmFtZSA9IG5hbWU7DQogICAgdGhpcy55ZWFyID0geWVhcjsNCg0KICB9DQogIGFnZSgpIHsNCiAgIC8vIGRhdGUgPSBuZXcgRGF0ZSgpOyAgLy8gVGhpcyB3aWxsIG5vdCB3b3JrDQogICBsZXQgZGF0ZSA9IG5ldyBEYXRlKCk7IC8vIFRoaXMgd2lsbCB3b3JrDQogICByZXR1cm4gZGF0ZS5nZXRGdWxsWWVhcigpIC0gdGhpcy55ZWFyOw0KICB9DQp9DQoNCm15Q2FyID0gbmV3IENhcigiRm9yZCIsIDIwMTQpOw0KZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoImRlbW8iKS5pbm5lckhUTUwgPQ0KIk15IGNhciBpcyAiICsgbXlDYXIuYWdlKCkgKyAiIHllYXJzIG9sZC4iOw0KPC9zY3JpcHQ+DQoNCjwvYm9keT4NCjwvaHRtbD4=