laika222
5/4/2017 - 7:38 PM

Create VARIABLE, INITIALIZE Variable, Reassign Value.html

<script language="javascript" type="text/javascript">

    var userName;              
    userName = 'Telson Smith';   
    document.write(userName);  
    userName = 'Johnny Smith';   
    document.write('<br />');  
    document.write(userName);  
    
</script>

<!-- DETAIL!!! -->

<script language="javascript" type="text/javascript">

    var userName;               // Variable Declaration, declares variable userName
    userName = 'Telson Smith';  // Variable Initialization, gives value to variable userName
    document.write(userName);   // Outputs value of variable in (), in this case userName
    userName = 'Johnny Smith';  // Variable Reassignment, changes value of variable userName
    document.write('<br />');   // Moves down a line in document
    document.write(userName);   // Outputs value of newly changed variable in () found in line 4 (userName=”Johnny Smith”)
    
</script>


<!-- Example of way to Declare and Initialize variable in single statement (i.e. create the variable and give it a value in one line -->

<script language="javascript" type="text/javascript">

var userName = 'Telson Smith';    // Declares variable userName and give it value 'Telson Smith'

</script>