return true or false at the end of the function

  • # November 29, 2012 at 9:22 pm

    hey how r you ? please check this, its a simple jquery.

    // scroll back to top btn
    $("html, body").animate({ scrollTop: 0 }, 1000);
    return false;

    this code is used to scroll top of a page slowly, i like it just one thing i dont understand why they use return false ? is it a good practice ? if yes then why ? i cut that but it still works without writing return false. i have seen this return true or false in many codes but i dont understand why they are used. will you please help me to know ?

    # November 29, 2012 at 10:22 pm

    It’s commonly used on click functions to stop the browser for doing its default behaviour.

    For example, if your `.scrolltop` element was an anchor tag, you’d have to put `#` as its `href` which would append the `#` to the URL. That’s not really what we want for the user to experience, so we make it not happen by returning false at the end up the function.

    This is not the best practice, though. For more info, this article is good reading:

    # November 30, 2012 at 12:43 am

    Thank you doc.

    # December 5, 2012 at 11:06 am

    great article doc thanks for sharing

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.