Results 1 to 3 of 3

Thread: what the alert messages would return when executed

  1. #1
    Join Date
    Jan 2008
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default what the alert messages would return when executed

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

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Hey, I have an idea, just try it!
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

    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>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •