Omitting the second expression when using the if-else shorthand

Can I write the if else shorthand without the else? var x=1; x==2 ? dosomething() : doNothingButContinueCode(); I’ve noticed putting null for the else works (but I have no idea why or if that’s a good idea). Edit: Some of you seem bemused why I’d bother trying this. Rest assured it’s purely out of curiosity. … Read more

Ternary operator in PowerShell

From what I know, PowerShell doesn’t seem to have a built-in expression for the so-called ternary operator. For example, in the C language, which supports the ternary operator, I could write something like: <condition> ? <condition-is-true> : <condition-is-false>; If that doesn’t really exist in PowerShell, what would be the best way (i.e. easy to read … Read more