odd JS behavior

Posted on
  • x = {"a":3};
    if (x.a) 4; else 5;
    

    run in node.js:

    > x = {"a":3};
    { a: 3 }
    > if (x.a) 4; else 5;
    4
    >
    

    run in espruino:

    >x = {"a":3};
    ={ "a": 3 }
    >if (x.a) 4; else 5;
    =undefined
    >
    

    similarly if (x.b) 4; else 5; returns 5 in node.js and undefined in Espruino.

  • I'm not sure what ECMA defines as 'return' from a statement. That's why some languages by definition return self / this except there is a coded return... a default return allows easy and especially with Espruino very fast cascading of messages sent / methods invoked to the very same object...

  • Interesting... I honestly wasn't aware that if statements returned anything - so it doesn't surprise me that it's wrong. It should be a pretty easy fix though. I just added a bug for this: https://github.com/espruino/Espruino/iss­ues/909

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

odd JS behavior

Posted by Avatar for tve @tve

Actions