This quiz evaluates your understanding of key Angular concepts and essential JavaScript fundamentals in preparation for 2025 interviews, focusing on best practices, language features, and framework architecture. Challenge yourself to identify correct options among realistic choices to sharpen your skills and gain confidence for technical assessment scenarios.
Which statement best describes how dependency injection works in Angular when providing a service at the root level?
Explanation: Providing a service at the root level in Angular ensures that only one instance is created and shared across the application, offering a singleton pattern. Option B is incorrect because a new instance is not created per component when provided in root. Option C misunderstands the scope of forChild; root-level providers bypass this. Option D is inaccurate because the service instance is injected wherever requested, not just the first component.
In the following scenario, what does the term 'closure' refer to in JavaScript? Example: A function defined inside another function, accessing variables from the outer function.
Explanation: A closure is when the inner function maintains access to its outer function's variables after the outer scope has exited, allowing data privacy. Option B describes function composition, not closures. Option C relates to immediately-invoked functions, which is different. Option D describes a possible bug but not closure behavior.
Which Angular lifecycle hook is called once after the first ngOnChanges and is commonly used for component initialization tasks?
Explanation: ngOnInit is executed once after the first ngOnChanges and is ideal for initializing component logic and data. ngDoCheck is called during every change detection cycle for custom checks. ngAfterViewInit occurs after component views are initialized, not specifically for initialization. ngOnDestroy is called just before the component is destroyed, suitable for cleanup, not setup.
When declaring variables in JavaScript, how does the scope of 'let' differ from 'var' inside a block, such as in an if statement?
Explanation: 'let' variables are limited to the block in which they are defined, such as an if or for block, while 'var' variables are accessible anywhere within the function. Option B is incorrect, as they do not have the same scope. Option C confuses function and global scope. Option D incorrectly restricts 'let' usage to arrow functions, which is not true.
Which type of data binding in Angular allows you to pass data from a parent component to a child component using property binding syntax?
Explanation: Input binding in Angular uses property binding to pass values from a parent to a child component, utilizing the input property decorator. Output binding is used for emitting events from the child to the parent. Two-way binding synchronizes data in both directions, but typically uses ngModel binding. Event binding only listens for outputs such as clicks, not data transfer from parent to child.