我正在学习灵丹妙药,我想知道在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
. Just like JavaScripts null
, you can use nil
as a "falsy" value in a boolean context, for instance:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.