Scope Skillz Exercise: Become a Scope Sniper

Bet you clicked this cause you are also a COD fan ?! :partying_face:

Came across this scope exercise which is great for thinking through scope ideas. This was definitely a two cup of coffee exercise.

var outside = ‘outside’;

function a( ) {
var a = ‘a’;

function aInner1( ) {
var aInner1Var = ‘aInner1Var’;
function aInner1Inner() {
var aInner1InnerVar = ‘aInner1InnerVar’;
function aInner2(aInner2Param) {
var aInner2Var = aInner2Param;
function b(bParam) {

Which of the following statements are true?

  1. a is visible to b
    2.b and bParam are visible to a
    3.Inner1InnerVar is only visible to aInner1Inner and aInner1
    4.aInner1InnerVar is visible to aInner1Inner
    5.aVar is visible to aInner2
    6.aInner1Var is visible to aInner2
    7.aInner2Param is visible to aInner1.
    8.None of the above.

The asnwers to this are 1 4 and 5.