what is the reason to use the bitwise OR (|) for the length
It's actually a performance thing...
Encountering this 0 | ... I removed the 0 | and first noticed a performance decrease timing 1K invocations... but later I felt not seeing it aymore and that's why I asked. The explanation makes it obvious... may be for compiled one should be able to provide type information for variables... to help the compiler a bit more... may be in the form of jsDoc... For running uncompiled it will (for sure) slow down the process... except something has changed in the upload to remove comments within a stament / function / object
var /*{String}*/ s = "Abc";
var /*{int}*/ len = s./*{int}*/length; // (or s/*{int}*/.length;
Similar approach for function signatures incl. return type.
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.
Encountering this
0 | ...
I removed the0 |
and first noticed a performance decrease timing 1K invocations... but later I felt not seeing it aymore and that's why I asked. The explanation makes it obvious... may be for compiled one should be able to provide type information for variables... to help the compiler a bit more... may be in the form of jsDoc... For running uncompiled it will (for sure) slow down the process... except something has changed in the upload to remove comments within a stament / function / objectSimilar approach for function signatures incl. return type.