-2
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.

Leon Gaban
  • 36,509
  • 115
  • 332
  • 529
  • 2
    As a rule of thumb: Don't use the conditional operator for side effects . – Felix Kling Feb 13 '16 at 17:37
  • @FelixKling you mean in the return statement? Could you explain? It seems to me that the equation check should be fine in the return, what would the side effects be? – Leon Gaban Feb 13 '16 at 17:41
  • The conditional operator produces a *value*. You should be doing something with that value, e.g. assign it to a variable, pass it do a function or use it as part of a larger expression. Example: `var result = someCondition() ? someValue : someOtherValue;`. If you don't do anything with the value, then don't use the conditional operator, but `if(...else)`. – Felix Kling Feb 13 '16 at 17:49
  • Ah got it... I am using the result as a `truthy` or `falsy` test to trigger or not trigger the next function. Felt I could skip the whole, `if / else return true, false` to save lines of code... – Leon Gaban Feb 13 '16 at 17:51

2 Answers2

4

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

if ( reachedBottom() ) loadMoreTags();
adeneo
  • 312,895
  • 29
  • 395
  • 388
  • @LeonGaban - most of the time, `if/else` is what is most useful, and readable. Often times, when you need to always return something based on a condition, like say `var x = bool ? 'a' : 'b'`, ternary operators are really neat. – adeneo Feb 13 '16 at 17:47
0

Could use logical AND operator &&

reachedBottom() && loadMoreTags()
guest271314
  • 1
  • 15
  • 104
  • 177