-2

I have some code examples like this

---------------------- First example -----------------

var rightFunction=function() {
        if (options.currentPage < options.numberOfPages) {
            options.currentPage += 1;
            ajaxConnection();
        }
        return false;
    };

    $('#newsContainer #rightSlider').click(rightFunction);
    $('#rightSliderHigh').click(rightFunction);

---------------------- Second example-------------------

 $('#rightSliderPagination').click(function(){
        if (parseInt(_pagina_last_link.html()) >= options.numberOfPages) {
            return false;
        }
        _first_page_num = parseInt(_pagina_first_link.html());
        paginationGenerator(_first_page_num + options.centerNumber - 1);
        $('#slider-inner').slider("option", "value", _first_page_num + options.centerNumber - 1);
        return false;
    });

------------------------Third example ----------------------

$(".download").click(function(){
        if($(this).attr('goToPage')=='true') {
            var url=$(this).attr('href');
            document.location.href=url;
            return false;
        }

        var _this = $(this);
        var thistext = $("#bg-download-box").html();
        var _whattoshow = $(this).parent().find(".what-to-show").html();

        if (_whattoshow){
            $("#bg-download-box form").html(_whattoshow);
        }

        else{
            $("#bg-download-box").html("<div id='bg-download-box-inner' style='height:132px'></div>");
        }


        if ($(".reccomend-box").length != 0){
        $("#rightColumn").css("z-index",99999);
        }

        $("#bg-download-box").show();
        var whattocopy = $("#bg-download-box");
        $(whattocopy).insertAfter(_this);
        $("ul#songs-list").css("z-index","99999");


        $("ul#songs-list li.b-a-r").removeClass("emph");

        $(this).parent().parent().parent().addClass("emph");
        return false;
    });

Why is return false is used at end of these functions. Please, somebody could explain the purpose of return false.

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

1

In Examples 2 & 3, the first return false is preventing the execution of any further code in the function.

In Example 1, it really doesn't do anything. I do this myself though sometimes, just out of habit and clarity sake for future programmers who read my code.

Chris Fremgen
  • 4,649
  • 1
  • 26
  • 26