[英]Elixir: what is the meaning of nil
我正在学习灵丹妙药,我想知道在JavaScript中nil
是否与null
相同,如果不是,那是什么意思?
They are similar, both are often used to denote the absence of a value. 它们是相似的,两者通常用于表示缺少值。 In JavaScript,
!!null
evaluates to false
, while in Elixir, !!nil
evaluates to false
. 在JavaScript中,
!!null
计算结果为false
,而在Elixir中, !!nil
计算结果为false
。 Just like JavaScripts null
, you can use nil
as a "falsy" value in a boolean context, for instance: 就像JavaScripts
null
,您可以在布尔上下文中使用nil
作为“falsy”值,例如:
if nil do
IO.puts "foo"
else
IO.puts "bar"
end
will print "bar" 将打印“酒吧”
I can't think of many differences between the two, other than perhaps a few corner cases. 我想不出两者之间的许多差异,除了一些极端情况。 For instance,
null > 0
evaluates to false
in JavaScript, while nil > 0
evaluates to true
in Elixir. 例如,
null > 0
在JavaScript中求值为false
,而nil > 0
在Elixir中求值为true
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.