How to get extension from input type file in JavaScript

Functions
By Jad Joubran · 
Last updated Dec 26, 2018
<input type="file" id="upload">
const upload = document.querySelector("#upload");

upload.addEventListener("change", event => {
  const file = event.currentTarget.value;
  if (!file) {
    return false;
  }
  const extension = file.substring(file.lastIndexOf(".") + 1);
});