admin管理员组文章数量:1418438
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 pile to:
var x;
x = truthy ? 'success!' : void 8;
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 pile to:
var x;
x = truthy ? 'success!' : void 8;
Share
Improve this question
edited May 30, 2014 at 17:35
Dormouse
5,1781 gold badge28 silver badges42 bronze badges
asked May 30, 2014 at 17:34
Jim O'BrienJim O'Brien
2,53718 silver badges29 bronze badges
5
-
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 Commented May 30, 2014 at 17:41 -
I guess it's the same reason most people use
void 0
. – Oriol Commented May 30, 2014 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 Commented May 30, 2014 at 17:44
- @BoltClock Sometimes really new is well forgotten old. – VisioN Commented May 30, 2014 at 17:46
-
I show my age, but to me 8 was always an error
JCL Return Code=8(Error)
– mplungjan Commented May 30, 2014 at 17:54
2 Answers
Reset to default 6From 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) piles to nothing (for use as a placeholder) - it must be used as a value to pile.
As for the 8
, it's an arbitrary number, and could have been set to any other. As per discussion in the ments 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
piles to. There just has to be some expression evaluated by the void
call.
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
本文标签: javascriptWhy does LiveScript use 39void 839 for undefined valuesStack Overflow
版权声明:本文标题:javascript - Why does LiveScript use 'void 8' for undefined values? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745266282a2650621.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论