Home arrow JavaScript arrow Page 4 - The Power of Javascript: Basic Types of Data
JAVASCRIPT

The Power of Javascript: Basic Types of Data


Javascript interpreters understand two different, basic types of data: numbers and character strings. But interpreters only understand these data types when they are presented in certain ways. This article, the third in a series, will explain what these types of data are, and how to handle them.

Author Info:
By: Michael Youssef
Rating: 3 stars3 stars3 stars3 stars3 stars / 28
July 12, 2005
TABLE OF CONTENTS:
  1. · The Power of Javascript: Basic Types of Data
  2. · Data as Numbers
  3. · Boolean Data, Yes or No
  4. · One Small Change

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
The Power of Javascript: Basic Types of Data - One Small Change
(Page 4 of 4 )

As you can see, the <br> tags are included inside the message boxes. Before we leave this section we will use something that is similar (in functionality) to the <br> tag that the message box will understand. Replace the code with the following:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Hello World</title>
<script language="JavaScript" type="text/javascript">
var aNumber;
alert("The variable aNumber = \n"+ aNumber);
aNumber = 123;
alert("The variable aNumber = \n"+ aNumber);
aNumber = "I'M NEW TO JAVASCRIPT";
alert("The variable aNumber = \n"+ aNumber);
</script>
</head>
<body>
</body>
</html>

Save and load the page, you will get the following three message boxes:

What we have done here is that we used the new line escape character, which the message box understands. We have placed the new line after the = sign in the string value, so the value of the variable aNumber prints at the next line. There's another thing that I would like to tell you in the following code:

aNumber = 123;
alert("The variable aNumber = \n"+ aNumber);

The first statement assigns the value 123 to the variable aNumber, and it should be familiar to you by now. The next statement concatenates the string value "The variable aNumber\n" with the number value 123, so the interpreter converts aNumber's value to a string value of "123" then concatenates it to the value:

"The variable aNumber = \n"

Then it displays the result. That's enough for now; we will talk about data type conversion in its own article.


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials