What is a auto global variables :- Geniusofstudent


If you assign a value to a variable that has not been declared(var), it will automatically become a GLOBAL variable.






Code:-

<!DOCTYPE html> 
<html> 

<head> 
 <meta name="viewport" content="width=device-width, initial-scale=1"> 
</head> 

<body> 
 <h1>Auto Global</h1> 

 <p>If you not assign var the variable is automatically converted to global variable</p> 

 <input type="button" onclick="cal_fun1();" value="Function 1"> 
 <input type="button" onclick="cal_fun2();" value="Function 2"> 

 <script> 
  function cal_fun1() 
  { 
   //not assign var so it is consider as global variable 
   carname = "bus"; 
   alert(typeof(carname)); 
  } 

  function cal_fun2() 
  { 
   alert(typeof(carname)); 

  } 
 </script> 

</body> 

</html>

What is a auto global variables :- Geniusofstudent What is a auto global variables :- Geniusofstudent Reviewed by Network security on June 09, 2019 Rating: 5

No comments:

Useful Information

Powered by Blogger.