Difference between revisions of "JavaScript Variable Types"

From Techotopia
Jump to: navigation, search
Line 12: Line 12:
 
<td>string<td>"Hello World!"<td>The ''string'' variable type stores a string of characters, typically making up either a word or sentence. ''string'' variables can also be assigned empty strings.
 
<td>string<td>"Hello World!"<td>The ''string'' variable type stores a string of characters, typically making up either a word or sentence. ''string'' variables can also be assigned empty strings.
 
<tr>
 
<tr>
<td>function<td>any built-in or user defined function<td>A function is one of the basic building blocks of most programming languages including JavaScript. Functions provide a way to organize functionality into clean, reusable modules that can be accessed from any other JavaScript to perform specific tasks. In addition to user created functions, JavaScript contains a number of built-in functions that provide pre-defined functionality. Functions are covered in a later chapter.</td>
+
<td>function<td>any built-in or user defined function<td>A ''function'' is one of the basic building blocks of most programming languages including JavaScript. Functions provide a way to organize functionality into clean, reusable modules that can be accessed from any other JavaScript to perform specific tasks. In addition to user created functions, JavaScript contains a number of built-in functions that provide pre-defined functionality. Functions are covered in a later chapter.</td>
 
<tr>
 
<tr>
 
<td>object<td>document, window<td>JavaScript provides a set of predefined objects to which the JavaScript programmer has access. For example the ''document'' object refers to the current web page and can be accessed to make changes to the page content.
 
<td>object<td>document, window<td>JavaScript provides a set of predefined objects to which the JavaScript programmer has access. For example the ''document'' object refers to the current web page and can be accessed to make changes to the page content.
 
</table>
 
</table>

Revision as of 20:07, 11 April 2007

JavaScript supports five different types of variable. These variable types are outlined in the following table together with examples and a brief description of each type:

TypeExampleDescription
booleantrue, falseThe boolean variable is used to record a value of either true or false. Internally this is essentially stored as 1 for true and 0 for false.
number1, -31, 0.023The number variable holds any type of number, either an integer or a real number.
string"Hello World!"The string variable type stores a string of characters, typically making up either a word or sentence. string variables can also be assigned empty strings.
functionany built-in or user defined functionA function is one of the basic building blocks of most programming languages including JavaScript. Functions provide a way to organize functionality into clean, reusable modules that can be accessed from any other JavaScript to perform specific tasks. In addition to user created functions, JavaScript contains a number of built-in functions that provide pre-defined functionality. Functions are covered in a later chapter.
objectdocument, windowJavaScript provides a set of predefined objects to which the JavaScript programmer has access. For example the document object refers to the current web page and can be accessed to make changes to the page content.