title: One-liner to set a variable value using a function and throw if it is falsy
body: <p>I find myself using the following pattern a lot when working with json data that may or may not be corrupt:</p>
  
  <pre class="lang-js prettyprint-override"><code>function getFooId(json) {
    const id = json.foo.id;
    if (!id) {
      throw Error(`foo.id has not been defined`);
    }
    return id;
  }
  </code></pre>
  
  <p>This seems overly verbose. I would like a one-liner along the lines of:</p>
  
  <pre class="lang-js prettyprint-override"><code>function getBarId(json) {
    return json.bar.id? json.bar.id : throw Error(`bar.id has not been defined`);
  }
  </code></pre>
  
  <p>Can this be done?</p>