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. |