> var name = Getname() ?? 'unknown' This `??` operator seems a bit unique to vim9script. If we're trying to be more like other languages how about either re-using `else` (as in Getname() else 'unknown') or using `or` (Like python): `Getname() or "unknown"`
On Sunday, October 4, 2020 at 10:47:15 PM UTC+1 Bram Moolenaar wrote: > > > In javascript you can use !! operator to always convert it to boolean. > > > > var name = '' > > var nameExists = !!(name || 'Prabir') > > Yes, and I think we should do the same. It should already work like > that now. > > Thus in most places where a condition is expected, such as with ":if" > and ":while", a boolean is expected. With legacy script you could use a > string, which was converted to a number and easily leads to mistakes. > Also numbers could be used. With Vim9 script only the numbers zero and > one can be used. This avoids making mistakes, but it's a bit strict. > > The new "??" operator can be used with any expression. Just like with > "!" accepts any expression. In these places the expression is tested to > be "falsy" or "truthy". > > I might have missed something, we might need a few more tests. > > > -- > hundred-and-one symptoms of being an internet addict: > 32. You don't know what sex three of your closest friends are, because they > have neutral nicknames and you never bothered to ask. > > /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\ > /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ > \\\ an exciting new programming language -- http://www.Zimbu.org /// > \\\ help me help AIDS victims -- http://ICCF-Holland.org /// > -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/b0bcb397-317c-4fa7-b42f-5ac6eebd3402n%40googlegroups.com.
