I have following code (based on this) in my custom step definition:
    $js = <<<JS
    function checkVisibility( elm, evalType ) {
        evalType = evalType || "visible";
        var vpH = jQuery(window).height(), // Viewport Height
            st = jQuery(window).scrollTop(), // Scroll Top
            y = jQuery(elm).offset().top,
            elementHeight = jQuery(elm).height();
        if (evalType === "visible") return ((y < (vpH + st)) && (y > (st - elementHeight)));
        if (evalType === "above") return ((y < (vpH + st)));
    }  
    var el = document.querySelector("$locator");
    return checkVisibility(el, "visible");
JS;
    $result = $this->getSession()->evaluateScript($js);
Similar code is working well in chrome console, but in Behat context $result is always null.
I'm using Behat: 3.0.15 with Selenium 3.4 and PhantomJS as a browser.
In general it seems that if I passing one-line code it's working ok. No matter what is inside my function, I've always null, so below code also result with null:
    $js = <<<JS
    function checkVisibility() {
      return true;
    }  
   // var el = document.querySelector("$locator");
    return checkVisibility();
JS;
 
    