1. What are the two predominant models for how Scope works used by the majority of programming languages?
your answer here
your answer here
var result = (function (a) {
function foo(b) {
return bar(5);
function bar(c) {
return a + b + c;
}
}
return foo(2);
})(3);
console.log(result);
your answer here
your answer here
NOTE: replace window
with global
if you are using node.js
var name = "John";
function foo(name) {
function bar() {
var name = "Doe";
return (function baz() {
return name;
})();
}
return bar();
}
console.log(foo(name));
your answer here
var a = 2;
console.log(window.a);
your answer here
function foo() {
var a = 3;
}
console.log(foo.a);
your answer here
function foo() {
// noop
}
foo.a = 4;
console.log(foo.a);
your answer here
var a = 5;
function foo() {
a = 10;
console.log(a);
console.log(window.a);
}
foo();
your answer here
"use strict";
function foo(str) {
eval(str);
console.log(z);
}
foo("var z = 4;");
your answer here
function foo(str) {
eval(str);
console.log(x);
}
foo("var x = 5;");
your answer here
function foo(str) {
eval(str);
}
foo("y = 7;");
console.log(y);
your answer here
function foo(str) {
eval(str);
}
foo("var y = 7;");
console.log(y);
your answer here
function foo(o) {
with (o) {
a = 5;
}
}
var obj = { a: 2 };
foo(obj);
console.log(obj.a);
your answer here
function foo(o) {
with (o) {
b = 10;
}
}
var obj = { a: 2 };
foo(obj);
console.log(obj.b);
your answer here
function foo(o) {
with (o) {
b = 5;
}
}
var obj = { a: 2 };
foo(obj);
console.log(b);
your answer here
function foo(o) {
with (o) {
b = 5;
}
}
var obj = { a: 2 };
foo(obj);
console.log(a);
your answer here
function foo(o) {
with (o) {
var b = 3;
}
console.log(b);
}
var obj = { b: 2 };
foo(obj);
your answer here
function foo(o) {
with (o) {
var b;
}
b = 3;
console.log(b);
}
var obj = { b: 2 };
foo(obj);
your answer here
function foo(o) {
with (o) {
var b = 3;
}
}
var obj = { b: 2 };
foo(obj);
console.log(b);
your answer here
function foo(o) {
with (o) {
b = 3;
}
}
var obj = { b: 2 };
foo(obj);
console.log(b);
your answer here
"use strict";
function foo(o) {
with (o) {
b = 3;
}
}
var obj = { a: 2 };
foo(obj);
console.log(b);
your answer here
your answer here
your answer here