The alert works in the following code if I remove the class declaration. I feel it should work with or without it. What am I missing?
class MyClass {
constructor MyClass() {
let x = 0;
}
}
alert("hi");
You have to remove the name MyClass in the constructor.
You can refer to the official documentation
class MyClass {
constructor () {
let x = 0;
}
}
alert("hi");
You just need to remove the class name from where you declare the constructor.
class MyClass {
constructor() {
let x = 0;
}
}
alert("hi");