Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Dec 2005
    Posts
    702
    Thanks
    0
    Thanked 0 Times in 0 Posts

    js : beginner's textbook questions : data types

    javascript : beginner's textbook questions : data types
    -----------------------------------------------------------------------
    result of below statements individually(?):
    typeof()
    parseInt(nine)

    what null defers from undefined ? null var declared but not give any value ? Or value is ="" ?
    How I use javascript to write an expression to convert decimal numbers to hexadecimal numbers ?

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Decimal to hexadecimal:-

    http://javascript.about.com/library/blh2d.htm

    result of below statements individually(?):

    <script language = "javascript" type="text/javascript">

    x = 123;
    alert (x + " " + typeof x);
    y = "456";
    alert (y + " " + typeof y);
    z = "nine";
    alert (z + " " + typeof z);
    zz = parseInt(z);
    alert (zz);
    var k;
    alert (k);
    var m = "";
    alert (m + " " + typeof m);

    </script>

  • #3
    Regular Coder
    Join Date
    Jun 2007
    Location
    USA
    Posts
    527
    Thanks
    26
    Thanked 74 Times in 72 Posts
    undefined means that the variable has had no value assigned to it:
    Code:
    var x;
    var y = {};
    alert(x); // undefined
    alert(y.absentValue); // undefined
    null is used in object situations. For example: Let's say that you have a function that searches for an object. What happens if that object does not exist? Return null

    In conditional situations, null, undefined, 0, "", and false all translate to false:
    Code:
    var falseVals = [null, undefined, 0, "", false];
    for(var i = 0; i < falseVals.length; ++i)
      if(falseVals[i])
        alert("true");
      else
        alert("false");
    If you want to make sure something exactly equals one of those values, you need to use the triple equality sign operator:
    Code:
    alert(undefined === false);
    alert(undefined === undefined);
     . . .
    Trinithis

  • #4
    Regular Coder
    Join Date
    Dec 2005
    Posts
    702
    Thanks
    0
    Thanked 0 Times in 0 Posts
    typeof()
    parseInt(nine)
    I try pseudo-javascript but no result ? tell me result ?

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Quote Originally Posted by lse123 View Post
    typeof()
    parseInt(nine)
    I try pseudo-javascript but no result ? tell me result ?
    Uh?

  • #6
    Regular Coder
    Join Date
    Jun 2007
    Location
    USA
    Posts
    527
    Thanks
    26
    Thanked 74 Times in 72 Posts
    Code:
    alert(typeof 4);
    alert(typeof "4");
    alert(typeof parseInt("34px"));
    Trinithis

  • #7
    Regular Coder
    Join Date
    Dec 2005
    Posts
    702
    Thanks
    0
    Thanked 0 Times in 0 Posts
    "Decimal to hexadecimal:-
    http://javascript.about.com/library/blh2d.htm " you said above, well,
    is this beginner's function (to js: "data types" start chapter) ?
    if not tell me expression to calculate this ?

  • #8
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Man all of your questions sound like you want pople to do your homework. Put some effort into answering them. You ight actualy learn something by looking up things!

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #9
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,459
    Thanks
    0
    Thanked 632 Times in 622 Posts
    parseInt is actually intended for converting between number bases. It takes two parameters the second of which should be a number between 2 and 36 to indicate the number base. If the second parameter is not specified then the base of the number will be worked out from the first one or two characters. If it starts with '0x' it will be assumed to be base 16 (hexadecimal - 0123456789ABCDEF), if it starts with '0' it will be assumed to be base 8 (octal - 01234567), only if it doesn't start with one of those will it be assumed to be base 10 (decimal - 0123456789).

    For converting strings to numbers there are a number of better ways than using the parseInt function. http://javascript.about.com/library/blstrnum.htm shows a variety of different ways to do it.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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