title: How do I parse a string to number while destructuring?
body: <p>I am trying to experiment around destructuring assignment. Now I have a case which I trying to cop up with destructuring itself.</p>
  
  <p>For example, I have an input like this:</p>
  
  <pre><code>let input = {latitude: "17.0009", longitude: "82.2108"}
  </code></pre>
  
  <p>Where <code>latitude</code> and <code>longitude</code> key values are strings, but I want to parse them into a number while destructuring.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>let input = {latitude: "17.0009", longitude: "82.2108"}
  let {latitude,longitude} = input
  
  console.log(typeof latitude,typeof longitude)</code></pre>
  </div>
  </div>
  </p>
  
  <p>I can see in <a href="https://babeljs.io/repl/#?babili=false&amp;browsers=&amp;build=&amp;builtIns=false&amp;spec=false&amp;loose=false&amp;code_lz=DYUwLgBAhgTjEF4IG9hTASzAVwCYgC4IAiARgHYA6ABloE5iAaCYAewDsBzLPQkgDgBMlQaWr9iAXwBQ00JFToe-Rmy7KQkxNDiygA&amp;debug=false&amp;forceAllTransforms=false&amp;shippedProposals=false&amp;circleciRepo=&amp;evaluate=true&amp;fileSize=false&amp;timeTravel=false&amp;sourceType=module&amp;lineWrap=true&amp;presets=es2015%2Creact%2Cstage-2&amp;prettier=false&amp;targets=&amp;version=7.3.4" rel="noreferrer"><strong>babel repl</strong></a> that this takes a reference of an object and then access each key. So the above code is the same as:</p>
  
  <pre><code>"use strict";
  
   var arr = {
     latitude: "17.0009",
     longitude: "82.2108"
    };
   var latitude = arr.latitude,
       longitude = arr.longitude;
  </code></pre>
  
  <p>I want do something like using the destructuring syntax itself.</p>
  
  <pre><code>"use strict";
  
  var arr = {
    latitude: "17.0009",
    longitude: "82.2108"
  };
  var latitude = Number(arr.latitude),
      longitude = Number(arr.longitude);
  </code></pre>
  
  <p>I am open to see some hacks too.</p>
  
  <p><strong>Update</strong></p>
  
  <p>I am able to come with up one hack with the <code>,</code> operator:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>let arr = {latitude: "17.0009", longitude: "82.2108"}
  
  let {lat,lng} = ({latitude,longitude} = arr, ({lat:+latitude,lng:+longitude}))
  
  console.log(typeof lat, typeof lng)</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong><em>On side note:-</em></strong> you must read <a href="https://stackoverflow.com/a/55197490/9624435">
  Moritz Roessler's answer</a> this is hacky but contains good knowledge and information</p>