function foo() {
	// In Lexical Scope environment a = 1
	// In dynamic Scope environment a = 3
	console.log(x);
}

function bar() {
	var x = 3;
	foo();
}

var x = 1;

bar();
function foo(code, x) {
	eval( code ); // cheating
	console.log( x, y );
}

var y = 2;

foo( "var y = 3;", 1); // 1, 3
var obj = {
	a: 1,
	b: 2,
	c: 3
};

// old way
obj.a = 2;
obj.b = 3;
obj.c = 4;

// using with()
with(obj) {
	a = 2;
	b = 3;
	c = 4;
}
function foo(obj) {
	with(obj) {
		a = 2;
	}
}

var o1 = {
	a: 3
};

var o2 = {
	b: 3
};

foo(o1);
console.log(o1.a); // 2

foo(o2);
console.log(o2.a); // undefined
console.log(a); // 2  which is the leaked global because of falling back to 
// global scope in absence of variable in current scope