How to define global variable in a JavaScript function?

JavascriptObject Oriented ProgrammingFront End Technology

To declare a global variable, use the var at global scope −

<script>
   var myGlobalVariable;
   function display() {
      //
   }
</script>

For JavaScript function, assign the property to a window −

<script>
   function display() {
      window. myGlobalVariable = …;
   }
</script>
raja
Published on 27-Feb-2018 10:44:25
Advertisements