I need a simple and short one liner to set, check, and possible use the return of a function.
The multi-liner issue is this...
var x = somelongwindedfunctionthatshouldnotbeusedmorethanonce();
if (x) console.log(x);
What I want to avoid:
if (somelongwindedfunctionthatshouldnotbeusedmorethanonce()) {
console.log(somelongwindedfunctionthatshouldnotbeusedmorethanonce()) };
Basically put, I only want to run the console.log IF there is a valid value.
If it is null or empty, then don't run it.
If it has a valid value, then use that function's value in the console.log to print it.
I'd like to avoid having to use or declare a variable. I'm open to arrow functions or anonymous functions, so long as it is short and neat and only uses the long-winded-function only once.
The function of console.log() is only a red herring example, I need this to work with any function.
Any genius ideas on how to one-liner check the variable before using it?
Ternary doesn't work, as I do not wish to set a variable. Only to check the output of a function before putting it into another function.
Help Please, thanks.