Complete the code to declare a namespace named 'Shapes'.
namespace [1] { export const pi = 3.14; }
The namespace is named 'Shapes' to group related constants and types.
Complete the code to add a function 'area' inside the 'Shapes' namespace.
namespace Shapes {
export const pi = 3.14;
export function [1](radius: number): number {
return pi * radius * radius;
}
}The function calculates the area of a circle, so it should be named 'area'.
Fix the error in merging two namespaces named 'Shapes'.
namespace Shapes {
export const pi = 3.14;
}
namespace Shapes {
export function [1](radius: number): number {
return Shapes.pi * radius * radius;
}
}To merge namespaces, both must have the same name 'Shapes'. The function inside the second namespace should be 'area' to calculate the circle's area.
Fill both blanks to create a merged namespace 'Shapes' with a constant and a function.
namespace [1] { export const [2] = 3.14; } namespace Shapes { export function area(radius: number): number { return Shapes.pi * radius * radius; } }
The first namespace must be named 'Shapes' to merge with the second. The constant inside should be 'pi' to be used in the area function.
Fill all three blanks to create a merged namespace 'Shapes' with a constant, a function, and a nested namespace.
namespace [1] { export const [2] = 3.14; export function area(radius: number): number { return pi * radius * radius; } export namespace [3] { export function circumference(radius: number): number { return 2 * Shapes.pi * radius; } } }
The outer namespace is 'Shapes'. The constant is 'pi'. The nested namespace is 'Circle' to group circle-related functions.