Either way will work, but using the setter method allows you to make sure that the property is set in a way that you intend.
With the numOfSensors property, if you set it directly using _numOfSensors, you can set it to anything - a string, Null, false, undefined, another object - there’s nothing to flag it as an error. By making a set numOfSensors method, you can check the input to make sure that it is a valid number before assigning it to _numOfSensors.
For example, you may have other code that depends on the _numOfSensors property, and maybe if _numOfSensors is accidentaly set to a string instead of a number that code will not work properly. If you give a setter method it’s less likely that the _numOfSensors property will be set to an invalid value, since the set method would catch the error.