Stimulus: this.has[Name]Value

I dont know why this.has[Name]Value always return true even I dont assign any value for this Value. It is set to empty string by default and then return true. So what is the purpose of this.has[Name]Value or I miss something?

Yeah, I agree, this doesn’t really make sense. Technically it “has” a value, even if it’s just the default value for the respective type. But given that this leads to the fact that it almost always returns true doesn’t really make this getter super useful. I’m wondering if we should change this behavior to make it check for a “custom set” value.

This existential operator is there so that you can make the value attribute optional in your data-controller signature. Imagine if you have some invocations of your controller (in your HTML) that define the value, and others that do not. Ordinarily, if you call the nameValue in your code, and that value wasn’t set on the HTML for the controller to read, you will get an error. But if you wrap that in a conditional expression, then it’s safe to use it both ways.