I have been using LiveScript for quite a while now, and I have noticed that in situations where undefined
would be implicitly returned, the expression void 8
is used instead.
Naturally, I understand the use of void
, but I cannot figure out why specifically the integer 8
is used.
For an example, the following LiveScript:
x = if truthy then \success!
Will compile to:
var x;
x = truthy ? 'success!' : void 8;
From the documentation on LiveScript, here's their reasoning for using void
rather than undefined
:
In JavaScript, undefined can be redefined, so it is prudent to use the void operator which produces the undefined value, always. void at the top level (not used as an expression) compiles to nothing (for use as a placeholder) - it must be used as a value to compile.
As for the 8
, it's an arbitrary number, and could have been set to any other. As per discussion in the comments below, the reason for this particular arbitrary number is because LiveScript is a fork of coco, whose wiki reports:
void 8 - the number 8 was chosen because it is a Chinese lucky number.
Regardless of how the developers chose the value, broadly speaking, it's just what the LiveScript void
compiles to. There just has to be some expression evaluated by the void
call.