You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • 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?

About

Avatar for Gordon @Gordon started