Challenge - 5 Problems
Namespace Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of accessing nested namespace value
What is the output of this TypeScript code using namespaces?
Typescript
namespace Outer {
export namespace Inner {
export const value = 42;
}
}
console.log(Outer.Inner.value);Attempts:
2 left
💡 Hint
Remember that exported members inside nested namespaces can be accessed using dot notation.
✗ Incorrect
The value 42 is exported inside the nested namespace Inner, which is inside Outer. Accessing Outer.Inner.value prints 42.
🧠 Conceptual
intermediate1:30remaining
Purpose of 'export' keyword in namespaces
In TypeScript namespaces, what does the 'export' keyword do?
Attempts:
2 left
💡 Hint
Think about how you can use a variable or function declared inside a namespace from outside it.
✗ Incorrect
The 'export' keyword allows members inside a namespace to be accessed from outside that namespace.
🔧 Debug
advanced2:00remaining
Identify the error in namespace usage
What error will this TypeScript code produce?
Typescript
namespace MySpace {
const secret = 'hidden';
}
console.log(MySpace.secret);Attempts:
2 left
💡 Hint
Check if the member is exported to be accessible outside the namespace.
✗ Incorrect
Since 'secret' is not exported, it is not accessible outside the namespace, causing a property error.
📝 Syntax
advanced2:00remaining
Correct syntax to declare a namespace with a function
Which option correctly declares a namespace with an exported function named greet?
Attempts:
2 left
💡 Hint
Remember the correct syntax for exporting a function inside a namespace.
✗ Incorrect
Option C correctly uses 'export function' syntax. Option C misses export, C has invalid syntax, D uses const which is valid but not the exact function declaration asked.
🚀 Application
expert2:30remaining
Number of accessible members after merging namespaces
Given these two namespace declarations, how many members are accessible from outside under the merged namespace 'Tools'?
Typescript
namespace Tools {
export function toolA() { return 'A'; }
}
namespace Tools {
export function toolB() { return 'B'; }
function hiddenTool() { return 'hidden'; }
}
// Outside the namespace
const count = Object.keys(Tools).length;Attempts:
2 left
💡 Hint
Only exported members are accessible outside. Hidden functions are not counted.
✗ Incorrect
The merged namespace 'Tools' has two exported functions: toolA and toolB. The hiddenTool is not exported, so only 2 members are accessible.