Nullish Coalescing Operator

Video

JavaScript Notes

JavaScript
    //because Node.JS does not support it as of v14.0.0
    //https://node.green/
    //https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator

    //var result = 'asdf' ? 'yes' : 'no'; //ternary - truthy or falsey

    //null or undefined
    let result = null ?? 'yes'; //'yes' if testing value was null or undefined

    let current;

    function f() {
        let result = current ?? getNum();
        console.log(result);
    }

    console.log(current);    // undefined at this point
    getNum();
    console.log(current);
    f();                     
    f();
    f();

    function getNum() {
        current = Math.floor(Math.random() * 100);
        return current;
    }