<===> input.scss
@function exists($name) {
  @return variable-exists($name);
}

@function f() {
  $foo: hi;
  @return g();
}

@function g() {
  @return variable-exists(foo);
}

div {
  foo: variable-exists(x);
  foo: variable-exists("x");

  span {
    $x: false;

    foo: variable-exists(x);
    foo: variable-exists("x");
    foo: variable-exists(y);
    foo: variable-exists("y");
    foo: exists(x);
    foo: exists("x");

    p {
      foo: variable-exists(x);
      foo: variable-exists("x");
      foo: exists(x);
      foo: exists("x");
      foo: variable-exists(y);
      foo: variable-exists("y");
      foo: f();
      $y: blah;
    }
  }

}
<===> output.css
div {
  foo: false;
  foo: false;
}
div span {
  foo: true;
  foo: true;
  foo: false;
  foo: false;
  foo: false;
  foo: false;
}
div span p {
  foo: true;
  foo: true;
  foo: false;
  foo: false;
  foo: false;
  foo: false;
  foo: false;
}