Angular and JavaScript Core Interview Questions 2025 Quiz

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.

  1. Angular Dependency Injection

    Which statement best describes how dependency injection works in Angular when providing a service at the root level?

    1. Angular creates a single instance of the service shared by the entire application.
    2. A new instance of the service is created for each component using it.
    3. The service is only available in modules imported with forChild syntax.
    4. Angular injects the service only into the first component that requests it.

    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.

  2. JavaScript Closure Concept

    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.

    1. A function automatically executing as soon as it is defined.
    2. A bug where variables are unexpectedly overwritten.
    3. The inner function retaining access to the outer function’s variables even after the outer function has executed.
    4. Merging two functions into one to save memory.

    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.

  3. Angular Lifecycle Hooks

    Which Angular lifecycle hook is called once after the first ngOnChanges and is commonly used for component initialization tasks?

    1. ngDoCheck
    2. ngOnDestroy
    3. ngOnInit
    4. ngAfterViewInit

    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.

  4. JavaScript let vs var Scope

    When declaring variables in JavaScript, how does the scope of 'let' differ from 'var' inside a block, such as in an if statement?

    1. 'let' variables are block-scoped, while 'var' variables are function-scoped.
    2. 'let' variables can only be used in arrow functions, while 'var' is for regular functions.
    3. 'var' variables are only accessible outside the function, while 'let' variables are not.
    4. Both 'let' and 'var' variables are block-scoped and work identically.

    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.

  5. Angular Data Binding

    Which type of data binding in Angular allows you to pass data from a parent component to a child component using property binding syntax?

    1. Event binding
    2. Input binding
    3. Output binding
    4. Two-way binding

    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.