how does file upload button work in js code example

Example 1: File Upload Button and display file javascript

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
  <label for="file-upload" class="custom-file-upload">
    <i class="fa fa-cloud-upload"></i> Upload Image
  </label>
  <input id="file-upload" name='upload_cont_img' type="file" style="display:none;">
</form>

Example 2: javascript upload file button

<input id='fileid' type='file' hidden/>
<input id='buttonid' type='button' value='Upload MB' />

Example 3: javascript upload file button

document.getElementById('buttonid').addEventListener('click', openDialog);

function openDialog() {
  document.getElementById('fileid').click();
}