how to create a global function in javascript and access local ?

JavaScript
function isValidRequired(input){
  input.value.trim() === '' || input.value.trim() === null;
}
  function checkNameReq(input){  
    if(isValidRequired(input)){
      alert('Error');
    }
    else{
      alert('Success');
    }
  }
Source

Also in JavaScript: