JavaScript Variables


You can create a variable with the var statement. Rules for variables include:
 var  strname = some value;
 <html><body>
  <script type="text/javascript">
   var  bool = confirm( "Go back to the previous page?" );
   if ( bool == true ) {
    window.location = document.referrer;
   }
   else if ( bool == false ) {
    document.write ( "<a href='" + document.referrer + "'>Back</a>" );
   }
  </script>
 </body></html>

The above script returns to the current page by using a boolean variable:
Demonstration