1

jsFiddle https://jsfiddle.net/d4rhf23x/

Issue: Everything is working as expected in terms of my scroll handlers, but if I do a manual of the object variable in question like so: console.log(site.globalVars.scrollY);, it does return the correct value, but then it also returns an undefined immediately afterwards.

Script:

<script>

    var site = {

        globalVars: {
            didScroll: false,
            scrollY: 0,
        },

        globalFuncs: {

            ifUserScrollsDoActions: function(){
                if ( site.globalVars.didScroll ) {
                    site.globalVars.didScroll = false;
                    site.globalVars.scrollY = window.scrollY;
                    console.log(site.globalVars.scrollY);
                }
            },

        },

        topMenuElements: {
            mobileMenuLink: document.getElementById('mobile-menu-link'),
        },

    };


    window.onscroll = function () {  
        site.globalVars.didScroll = true;
    }

    setInterval(function() {
        site.globalFuncs.ifUserScrollsDoActions();
    }, 250);


</script>
HC_
  • 1,040
  • 10
  • 23

1 Answers1

4

When you call console.log as a function it logs the parameters to the console.

When you call console.log as a function from the console, it treats it like any other function in the console, and logs the return value.

console.log returns undefined.

zzzzBov
  • 174,988
  • 54
  • 320
  • 367