Search code examples
javascriptternary

How to edit this javascript ternary function to return nothing if first result is false?


function scrollTagsPanel(event) {

    reachedBottom() ? loadMoreTags() : console.log('keep scrolling');

    function reachedBottom() {
        return tagsCol.scrollHeight - tagsCol.scrollTop === tagsCol.offsetHeight;
    }

    function loadMoreTags() {
        console.log('load more...');
    }
}

Since reachedBottom() will only return if you hit the bottom, I need something to fill in the false part ie: console.log('keep scrolling'); I tried using return; but that threw an error and I can't leave that part blank. And rather not have a an empty function there.


Solution

  • Why not just use a regular if condition, that's what it's for

    if ( reachedBottom() ) loadMoreTags();