I'm learning elixir and I was wondering if nil is the same as null in JavaScript, if not, what is the meaning?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With