Site hosted by Angelfire.com: Build your free website today!
 
MyersDaily Directories
What's Up Bottom of Page
[Pages][Home]

Beginning JavaScript® Vocabulary

Variables
   Declaring a variable:
   
   var variablename = valueofvariable;
   
   var "declares" a new variable.
   valueofvariable represents some form of data -- a string, array, object, etc.

   The text variablename represents a variable name which can consist of letters, numbers and
   underscores, but not any plain numbers. (You couldn't set 50 to 'hi' since 50 already literally means 50.)
   No spaces are allowed in variable names.
Operators
   Basic operators:
   
   +  (addition)  -  (subtraction)  /  (division)  *  (multiplication)  %  (modulus)
   
   The plus sign + adds two numbers or concantanates strings.
   
   5 + 5 = 10,  'everyone' + ' likes you' = everyone likes you,  '5' + 12 = "512".
   
   Note: Since the plus sign (+) performs a dual role, a string "5" + 10 [a number] equals "510" not 15.


   The minus sign (-) performs subtraction.
   
   500 - 21 = 479,  'everyone' - ' likes you' = NaN,  '5' - 12 = -7.
   
   Note: Since the minus sign - doesn't perform a dual role, a string "5" - 10 (a number) equals -5.
   Subtracting text from text results in the NaN value (Not a Number).


   The division symbol (/) performs division.
   
   1000 / 10 = 100,  'everyone' / ' hates you' = NaN,  '5' / 12 = 0.4166666666666667.
   
   Note: The NaN value is also returned as with the minus sign when used with text strings.
   The multiplication and modulus operators will also return NaN when using non-numbers.


   The multiplication symbol (*) performs multiplication.
   
   547 * 623.7 = 341163.9, '17' * 16 = 272.


   The modulus symbol (%) performs the modulus function.
   
   29 % 7 = 1, 13 % 13 = 0.
   
   Note: The modulus function returns the remainder of the division between the two numbers.
   (99 / 34 = 2 remainder 31.)
Today's script
<script language=javascript>
<!-- // hide from old browsers

var twenty = 20;                  // Setting a new variable here.

var addition = twenty + 10;       // This would be 30.

var subtract = twenty - addition; // This would be negative 10 (-10);

var division = twenty / 5;        // This would be 4;

var multiply = twenty * 6;        // This would be 120;

var aModulos = twenty % 6;        // This would be 2;

// End of hiding -->
</script>
Enter keywords...  
Amazon.com logo Send to a friend!

Home | Top | Feedback | Site Index | Best Pic

“MyersDaily” created by Joseph K. Myers 1999-2000. Free hosting by Angelfire!!
Note: This site's URL is (<https://www.angelfire.com/yt/jmyers/>).
Last update: April 15, 2000