C() and D() are local functions that are private to the scope of B(). They are like local variables. They only exist within the scope of B(). That is how the scoping in Javascript works.
You cannot access them outside of B() unless you pass references to them to other functions, return them from the function or you change the structure so they are declared or assigned to to a higher level scope rather than inside of B().
For example, you can pass a reference to them to another function:
function B() {
function C() { console.log('c'); }
function D() { console.log('d'); }
console.log('b');
setTimeout(C, 1000);
}
Then, when you call B(), it will first output b and then 1 second later it will output c.
Or, you could change their structure by making those functions be properties of the B function object:
function B() {
B.C = function() { console.log('c'); }
B.D = function() { console.log('d'); }
console.log('b');
}
Then, you can call B() or to get access to C or D, you call them like B.C().
Or, you could return an object from B() that had both functions on it:
function B() {
var obj = {};
obj.C = function() { console.log('c'); }
obj.D = function() { console.log('d'); }
return obj;
}
var functions = B();
functions.C();
Or, you can make B() be a constructor function:
function B() {
this.c = function() { console.log('c'); }
this.d = function() { console.log('d'); }
return obj;
}
var obj = new B();
obj.c();
FYI, a regular convention in Javascript is that constructor functions start with a capital letter and other functions/methods start with a lowercase letter.
var) have the same scope - the identifier is bound to the enlcosing function block. Generally an aggregate group of functions is exposed via properties of a returned objects.