11

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;
Dormouse
  • 5,130
  • 1
  • 26
  • 42
Jim O'Brien
  • 2,512
  • 18
  • 29
  • With some imagination, `void 8` reads like "voided". That must be it :P In any case, that's one of these questions you should ask the developers directly. – Felix Kling May 30 '14 at 17:41
  • I guess it's the same reason most people use `void 0`. – Oriol May 30 '14 at 17:42
  • 3
    I was thoroughly and hopelessly confused when I first saw this question because LiveScript was the original name of JavaScript in early Netscape builds where the scripting language first appeared and I was wondering what on earth someone was doing writing code for pre-NN4. So it turns out there's a new language, based *on* JavaScript, that goes by the name LiveScript... go figure. – BoltClock May 30 '14 at 17:44
  • @BoltClock Sometimes really new is well forgotten old. – VisioN May 30 '14 at 17:46
  • I show my age, but to me 8 was always an error `JCL Return Code=8(Error) ` – mplungjan May 30 '14 at 17:54

2 Answers2

6

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.

Sam Hanley
  • 4,707
  • 7
  • 35
  • 63
3

Most probably 8 is the favourite number of the developer (or just a random number), as whatever you put after void operator, you'll receive pure, not overridden undefined.

Simple test:

void 0    === void 8    =>    true
void 'a'  === void 8    =>    true
void true === void 8    =>    true
VisioN
  • 143,310
  • 32
  • 282
  • 281