The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript return true or false at the end of the function

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #41069

    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 ?


    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:


    Thank you doc.


    great article doc thanks for sharing

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.