title: Getting port from URL string using Javascript
body: <p>I would like a function in javascript that will get as a parameter an url and will return the port of that URL as it follows:</p>
  
  <ul>
  <li>If there's a <code>http</code> or <code>https</code> <em>(port 80 / 443)</em> it won't be shown in url structure but I want them returned anyway.</li>
  <li>If there's another port, I want that to be returned.</li>
  </ul>
  
  <p>Example:</p>
  
  <pre><code>function myFunction(url){
      something here
      ...
      return port
  }
  </code></pre>
  
  <p>I've seen that this can be done easy using some additional libraries but I do not want to use one. I didn't work with js since now and I would really appreciate if somebody will also be able to explain his solution.</p>