The built-in pins are a special Pin type, but they can also be converted to numbers.
For instance: digitalWrite(1,0) does the same as digitalWrite(D1,0) (on many platforms) to behave the same as on Arduino.
That means that D3==3 and D0==0 - and when you convert a pin to a boolean, there's no specific conversion for bools so it's converted to an integer first, which is then converted like an integer would be (eg !!D0==!!0==false).
If you want to check if a pin is defined, it's best to do pin!==undefined
Having said all that, JS does have some hacks in it - for instance "0"-0==0 but !!"0"==true - so it may make sense to add similar functionality to Espruino?
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
The built-in pins are a special
Pin
type, but they can also be converted to numbers.For instance:
digitalWrite(1,0)
does the same asdigitalWrite(D1,0)
(on many platforms) to behave the same as on Arduino.That means that
D3==3
andD0==0
- and when you convert a pin to a boolean, there's no specific conversion for bools so it's converted to an integer first, which is then converted like an integer would be (eg!!D0==!!0==false
).If you want to check if a pin is defined, it's best to do
pin!==undefined
Having said all that, JS does have some hacks in it - for instance
"0"-0==0
but!!"0"==true
- so it may make sense to add similar functionality to Espruino?