What is the proper way to check if a particular variable is null? I use v:null
as a special value to indicate something in a custom function's return value.
I have tried:
let l:v = v:null
echom l:v == v:null " Works fine
let l:v = {'file': "something"}
echom l:v == v:null " E735: Can only compare Dictionary with Dictionary
Note for searchers: null is sometimes called None, empty or nil.
is
instead of==
(can't test rn).echom !(l:v is v:null)
isnot
. I'm writing an answer.is#
even when it's not needed, and almost never write==
. Then I have less thinking to do, and I don't get weird conversions I don't want (strings and numbers). This is likely because Martin persuaded me with the article linked in the answer.