PDA

View Full Version : what the alert messages would return when executed



swathi
01-22-2008, 06:46 PM
<script type="text/javascript">
var a = "123";
b = 123;

function test(){
b = parseInt(a);
a += 1;
c = "babe";
var d = "ruth";
}

alert(typeof(a));
alert(typeof(b));
alert(typeof(c));
alert(typeof(d));
test();
alert(typeof(a));
alert(typeof(b));
alert(typeof(c));
alert(typeof(d));
</script>

jscheuer1
01-22-2008, 07:03 PM
Hey, I have an idea, just try it!

jscheuer1
01-22-2008, 07:16 PM
Here's the results I got:


before typeof(a)=string
before typeof(b)=number
before typeof(c)=undefined
before typeof(d)=undefined
after typeof(a)=string
after typeof(b)=number
after typeof(c)=string
after typeof(d)=undefined

from this code:


<div id="result">

</div>
<script type="text/javascript">
var a = "123";
b = 123;

function test(){
b = parseInt(a);
a += 1;
c = "babe";
var d = "ruth";
}

function disp(s, t){
document.getElementById('result').innerHTML += s + t + '<br>';
}

disp('before typeof(a)=', typeof(a));
disp('before typeof(b)=', typeof(b));
disp('before typeof(c)=', typeof(c));
disp('before typeof(d)=', typeof(d));
test();
disp('after typeof(a)=', typeof(a));
disp('after typeof(b)=', typeof(b));
disp('after typeof(c)=', typeof(c));
disp('after typeof(d)=', typeof(d));
</script>