(3).constructor is Number, but "constructor" in (3) is TypeError, why?
With using the property accessor, the number 3 is turned into an object of Number. And an object of that type has a constructor and thus an constructor property.
But as ChaosPandion already pointed out, the in operator requires the right expression to yield an object but 3 is not an object but a plain number literal.
The specification for the in operator explains this. Specifically, see step 5 of semantic evaluation.
11.8.7 The in operator
The production RelationalExpression : RelationalExpression in ShiftExpression is evaluated as follows:
The reason (3).constructor works is a a bit more challenging to understand but essentially when you use the dot operator on a reference with a primitive base it gets lifted into an object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With