www.webdeveloper.com
Results 1 to 2 of 2

Thread: javascript doubt

  1. #1
    Join Date
    Mar 2012
    Posts
    5

    javascript doubt

    <script type="text/javascript">
    var num=["12","23","5","14"];
    function sortNumber(a,b)
    {
    return a-b;

    }

    document.write(num.sort(sortNumber());
    </script>
    //when i call the above function it returns a sorted array,,how it works?????,,
    bcoz i don't pass any parameter in my FUNCTION CALL!!!!!

  2. #2
    Join Date
    Feb 2010
    Location
    Amsterdam
    Posts
    174
    thats because your passing your function as a parameter to the array sort function

    and the array sort methods provides a & b

    http://www.javascriptkit.com/javatutors/arraysort.shtml (note that you can omit the () from sortNumber example:
    Code:
    num.sort(sortNumber);
    )

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles