Published July 03, 2024

Angujlar - Single Page Application

Angular is one of the most widely used frontend technologies. Let's test our knowledge of Angular with multiple-choice questions, each offering four options. Select the answers based on the given scenarios.

image

Multiple-choice questions and correct answers with explanations:

1. Data Types in TypeScript (Used in Angular)

1. Which of the following is not a primitive data type in TypeScript?
   A) number
   B) string
   C) boolean
   D) object

2. How do you define an array of strings in TypeScript?
   A) let arr: string[] = ["a", "b", "c"];
   B) let arr: Array<string> = ["a", "b", "c"];
   C) let arr: [string] = ["a", "b", "c"];
   D) Both A and B
 

3. What is the correct way to define a tuple in TypeScript?
   A) let tuple: [string, number] = ["hello", 10];
   B) let tuple: (string, number) = ["hello", 10];
   C) let tuple: [string; number] = ["hello", 10];
   D) let tuple: {string, number} = ["hello", 10];

4. Which of the following denotes an object type with specific properties in TypeScript?
   A) let obj: { name: string, age: number };
   B) let obj: (name: string, age: number);
   C) let obj: [name: string, age: number];
   D) let obj: { name; string, age; number };

5. How do you define a function type in TypeScript that takes a number and returns a string?
   A) let myFunc: (x: number) => string;
   B) let myFunc: (x: number): string;
   C) let myFunc: {x: number}: string;
   D) let myFunc: [x: number]: string;

6. What is the TypeScript type for a variable that can hold any value?
   A) any
   B) unknown
   C) object
   D) void
 

7. Which of the following types represents the absence of a value?
   A) null
   B) undefined
   C) void
   D) All of the above

8. How do you declare a constant variable in TypeScript?
   A) const PI: number = 3.14;
   B) let PI: number = 3.14;
   C) var PI: number = 3.14;
   D) PI: number = 3.14;

9. What is the result of the following TypeScript code? let x:any = "Hello"; x = 10;
   A) Compile-time error
   B) Runtime error
   C) No error, x can be reassigned to any type
   D) Undefined behavior

10. Which TypeScript feature allows a variable to hold more than one type?
    A) Union types
    B) Intersection types
    C) Any type
    D) Tuple types

11. What is the correct way to cast a variable to a specific type in TypeScript?
    A) let str = <string>someVariable;
    B) let str = someVariable as string;
    C) Both A and B
    D) Neither A nor B

12. How do you define an interface in TypeScript?
    A) interface Person { name: string; age: number; }
    B) class Person { name: string; age: number; }
    C) type Person = { name: string; age: number; }
    D) let Person = { name: string; age: number; }

13. Which TypeScript type is used for a variable that can be a function or null?
    A) Function | null
    B) any
    C) unknown
    D) object

14. How do you define an enum in TypeScript?
    A) enum Direction { Up, Down, Left, Right }
    B) const Direction { Up, Down, Left, Right }
    C) let Direction = { Up, Down, Left, Right }
    D) var Direction { Up, Down, Left, Right }

15. Which of the following correctly defines a generic function in TypeScript?
    A) function identity<T>(arg: T): T { return arg; }
    B) function identity(arg: any): any { return arg; }
    C) function identity<T>(arg: any): any { return arg; }
    D) function identity(arg: T): T { return arg; }


2. Angular Interpolation


1. What is Angular interpolation used for?
   A) Binding properties of DOM elements to component data
   B) Executing component methods
   C) Embedding dynamic expressions in the HTML template
   D) Creating new Angular components

2. Which of the following is the correct syntax for Angular interpolation?
   A) {{ value }}
   B) [[ value ]]
   C) { value }
   D) ( value )

3. What will be the output of {{ 2 + 2 }} in Angular?
   A) 22
   B) 4
   C) {{ 2 + 2 }}
   D) Undefined

4. Can you call a method within an Angular interpolation expression?
   A) Yes, you can call methods within interpolations.
   B) No, methods cannot be called within interpolations.
   C) Only if the method is an arrow function.
   D) Only if the method returns a string.

5. What will be the output of {{ user.name }} if user is { name: 'John' }?
   A) user.name
   B) {{ user.name }}
   C) John
   D) Undefined

6. Which of the following is NOT a valid Angular interpolation expression?
   A) {{ 'Hello ' + name }}
   B) {{ name ? 'Hi ' + name : 'Hi' }}
   C) {{ user['name'] }}
   D) {{ name && age }}

7. How do you display a component's property using interpolation?
   A) [property]
   B) {{ property }}
   C) { property }
   D) (property)

8. Which of the following expressions will correctly display a user's full name?
   A) {{ user.firstName + ' ' + user.lastName }}
   B) {{ user.firstName user.lastName }}
   C) {{ user.firstName, user.lastName }}
   D) {{ user.firstName & user.lastName }}

9. What will be the result of `{{ 5 > 3 }}` in Angular interpolation?
   A) 5 > 3
   B) true
   C) false
   D) Undefined

10. How do you format a date using interpolation in Angular?
    A) {{ date | date:'shortDate' }}
    B) {{ date.date:'shortDate' }}
    C) {{ date shortDate }}
    D) {{ date, 'shortDate' }}

Download Lecture Pdf..

Reviews

Leave a Comment