Subscribe to Get Free Material Updates!
Visit my new blog WebData Scraping - Web Scraping Service provider company in India.

Variable’s Type can be Changed on The Fly In JavaScript


Program Definition: Write a JavaScript that shows how a variable’s type can be changed on-the-fly.
Explanation:

Almost everything you want to do in JavaScript is going to involve moving data from one variable to another variable, otherwise manipulating the value of variables. In JavaScript much of the information holds in variables. The JavaScript is “loosely typed”  language like PHP, means any type of value can be assigned to a single variable without specifying datatype, is called changed on fly.

Changing on the fly means that if you start with a variable holding numeric value and use it in calculation and later you store string value in the same variable. The following JavaScript example demonstrates you How variable's type changed on the fly.

Prog1.html
<html>
<head>
<title>How Variable Change on the Fly in JavaScript</title>

<script language="javascript">
document.write("<h1>How Variable's Type Change on Fly</h1>");
document.write("<b>At the starting the valu of variable n1 is numeric</b><br/>");
n1=60;
document.write("Value of n1="+n1+"<br/>");
document.write("<b/>Then we assigned the string value to the same variable n1</b><br/>");
n1="Hello JavaScript";
document.write("Value of n1="+n1+"<br/>");

document.write("<b>Now we again assigned Floating value to the variable n1</b><br/>");
n1=50.12
document.write("Value of n1="+n1+"<br/>");

document.write("<h4>This way we can assigned any type of value to same <br>variable is calles variable value change on The Fly</h4><br/>");
</script>
</head>
<body>

<a href='http://www.gtuguru.blogspot.com'>For More Examples and Materials Visit GTU Guru</a>
</body>
</html>

Output on Web Browser:

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...

 
Design by Wordpress Theme | Bloggerized by Free Blogger Templates | coupon codes