Typescript and Angular Flashcards

1
Q

What is the general structure of an HTML document and what are the different parts of the document used for?

A

The Html document is divided into several parts, these are head part and body part. In the head part there is a <title> tag that we use to give a title for the page and it is visible on the web browser url. And also, we can add css styling in the head part. The body part is where we design the structure of the webpage by using different tags.</title>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are some HTML elements you’ve used?

A

Some elements that I used are <div>, <p>, <ul> <section> , <h1> and more

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are inline and block elements?

A

Inline elements are those which do not start a new line and take up to the width of the content of the element

While block elements are those which start on a new line and take a full width of the available space. Moreover, we can have inline block elements inside the block elements, but we cannot have block elements inside inline elements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the purpose of assigning ID’s and Classes to elements?

A

The purpose of assigning id’s and classes to elements is that they will use for the purpose of styling and for Js functions. For example, we can select elements by their id and implement styling for that specific id content or we can add interaction for that specific element in JS by selecting the element by its id.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do I create an ordered list or an unordered list?

A

We can create ordered list by using <ol> tag and we can also create an unordered list by using <ul> tag. For both lists we can use <li> tag to display the lists

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What new features were introduced in HTML5?

A

Vector Graphics, Audio and video, preload videos, regular expressions, nav tag, email attribute.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How can I attach Javascript to an HTML file?

A

We can attach Js to html using the

 tag. We can either embed Javascript direcly into the HTML inside script tag: `
const js = “Javascript code”
`, or more likely link to an external file containing our js source using the “src” attribute: `<script src=jscode.js>
`.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is CSS?

A

Cascading style sheet; determines how a given element is presented on a webpage; gives more control over the appearance of a webpage to the creator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the three different ways to apply CSS to HTML elements? Which one takes priority?

A

Inline (Highest Priority): Applied directly to an HTML element using the “style” attribute.
Internal: Internal styles are defined within the head section of an HTML document.
External: External styles are defined in a separate CSS file and linked to your HTML document.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the different ways we could select HTML elements for applying styling rules? How are they prioritized?

A

Element Selectors
Class Selectors
ID Selectors
Attribute Selectors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the CSS box model?

A

CSS box model is a container that has(contains) multiple properties like borders, margin, padding, and the content. It is used to create the layout of webpages.

Content: displays text, images

Padding: creates space around the elements

Border: surrounds the content and padding it can be styled with color and width

Margin: create space around the border.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is responsive web design?

A

RWD (Responsive Web Design) is the development of a website that responds to accommodate to different screen sizes and orientations. To achieve this we need to implement flexible layouts, media queries and flexible media.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Could you provide a short description of Javascript?

A

JavaScript is a dynamic and loosely typed programming language. It is used for web development, it allow us to implement dynamic features on web pages. Also runs on a single thread with an event loop handling events

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does it mean for Javascript to be loosely typed?

A

Loose typing means that no type checking of data fields is performed, which can lead to errors/undefined behavior when a certain type is expected, but data of another type is received. For example, if you expect two numbers but you get strings and then divide them by each other.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does it mean for Javascript to be interpreted?

A

Javascript does not need to be compiled to be run. It is immediately run by the browser without any conversion into another language.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the types in Javascript?

A

The primitive types are:

Null – A singleton set representing a null value

Undefined – A singleton set representing an undefined value

Boolean – A binary state consisting of either true or false

Number - Equivalent to a double in java, i.e. 64-bit IEEE 754 floating point.

BigInt – An integer (whole number) value having arbitrary size/precision. Unlike in java where an int is of size 4 (32 bits).

String – A sequence of UTF-16 encoded characters. Practically identical to Java String.

Symbol – A guaranteed unique key value used for Objects.

Plus programmer defined Objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is type coercion in Javascript?

A

The conversion of values from one data type to another (such as strings to numbers).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What are truthy and falsy values in Javascript?

A

Truth values are values that evaluate to true in context of a boolean.
Example of falsy values:
false
0
-0
“”
null
undefined
NaN

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is the difference between == and === in Javascript?

A

Tripple equals “===” checks for strict equality, so will return false if the operands are of different types. This is unlike double equals “==” which will attempt to coerce the operands to compare them.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What are the different ways to declare a variable in Javascript?

A

let – Declares a variable following normal block scoping rules.

var – Like let, except scope is global; not confined to it’s defining block. – hoisted to the top of the file

const – Immutable: cannot change value or be redefined. Similar to let in scoping rules.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What are callback functions in Javascript?

A

Is a function that is passed as an argument to another function, and it is called after the main function has finished its execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is the DOM?

A

Document Object Model is the representation of the HTML document in memory. its generated and can be manipulated by web API’s to change the look of the page as it is being viewed. When a web page is loaded the browser will load a DOM for that page and it allows Js and other programing languages to access and manipulate the content of the page.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

How can I select & modify HTML elements in Javascript?

A

document.getElementById, document.querySelector(), document.querySelectorAll(), document.getElementByClassName().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

How can I have Javascript execute some function when a button is clicked?

A

Use an event listener on that variable on two different ways. I can use button.onclick() or cutton.addEventListener (“click”, functionname()).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What is an EventListener and why is it used?

A

It is a build in function in JS that allows us to wait for user interaction to then run some code. We normally use it on buttons, inputs, or when a user types or clicks on the screen so we could then do something.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What is bubbling & capturing?

A

Bubbling happens when an element receives and event, and that event is propagated to its parent and ancestor elements in the DOM. Capturing is when the event is first captured by the outermost element, then propagates to the inner elements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

What is the event loop in Javascript?

A

Responsible for executing the code, collecting and processing events, and executing queued sub-tasks

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What are Promises, what are they used for?

A

A promise is the object that represents the eventual completion or failure of an asynchronous process and its result

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What do Async & Await do in Javascript?

A

Async and await are tags you can use on methods and processes inside methods to let it know that it’s an asynchronous operation and enables promise-based behavior in a cleaner style

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

What features were introduced in Javascript version ES6?

A

-Const: Variables
-Let: Variables
-Arrow functions:
-Template literals:
-Default parameters: Allows you to define a parameter in advance. Function parameters are defaulted to undefined but now you can set different default values.
-Object and Array Destructing: We can ‘unpack’ array objects into a bunch of variables. Instead of declaring variables separately for each property of an object, we put our values within curly brackets to get any property of the object. Variable = { object: ‘value’, ‘object:value}
-Classes: Can be used to create new Objects with the help of a constructor, each class can only have one constructor insdie it.
-Rest Parameter: Allows us to represent an indefinite number of arguments as an array. Functions can be called with any number of arguments, no matter how it was defined. Function func(…variable){}
-Spread Operator: Allows us to obtain a list of parameters from an array.

31
Q

What are arrow functions?

A

A more concise way for writing function expressions.

32
Q

What are template literals?

A

A new form of making strings that allow creating multi-line strings more easily and using placeholders to embed expressions in a string.

33
Q

What is a closure in Javascript?

A

Closure makes it possible for a function to have “private” variables. It allows a function to have access to the parent scope, even after the parent fuction has closed.

34
Q

What is the fetch API?

A

The Fetch API is a promise-based interface for fetching resources by making HTTP requests to servers from web browsers. We can use the FETCH() method, it will allow us to fetch data from different places and work with the fetched data.

35
Q

What is Node.js and why do we use it? How does it different from our previous way of running Javascript?

A

Node.js is a server-side way of running JavaScript code, it allows us to use JS on both front and backends. Without Node, JS is run only on a client’s web browser.

36
Q

What is NPM?

A

A dependency management tool that allows us to easily install the packages needed to run a program with Node.js. Stands for Node Package Manager.

37
Q

What is the package.json file?

A

It lists all of the dependencies and their versions that are needed to develop and run JS projects, it is used by NPM.

38
Q

What is Typescript and why do we use it?

A

Typescript is a superset of javascript.It adds types to javascript. By allowing types ts helps to identify errors in the code at compile time.

39
Q

What is transpilation? What command is used to transpile Typescript?

A

Compiling Typescript to javascript and it’s various versions is called Transpiling. The command used is npx tsc

40
Q

What types does Typescript introduce that Javascript does not have?

A

Static typing - TypeScript supports static typing and errors are highlighted during the development phase itself.

41
Q

What features does Typescript introduce other than strong typing?

A

Typescript allows for stronger OOP through the introduction of interfaces and access modifiers.

42
Q

Why would we use interfaces in Typescript?

A

TS interfaces allow users to define their own objects used in the code.TS compiler uses interfaces for Type checking to check if the object has a specific structure or not.This type checking is also called duck typing or structural subtyping.

43
Q

What is a decorator?

A

A decorator is a function that we use to attach metadata to a class declaration, method, accessor, property, or parameter. Examples would be something like @Component, @Input, @Output

44
Q

What’s a component in angular?

A

Component is a building block used to create our application, which allows to break down an application into smaller and reusable parts, as a result it is easier to maintain and update.

45
Q

What files does a component contain?

A

Component.css, component.html, component.spec.ts, component.ts, And component.css

46
Q

What’s a service in angular? What’s special about them?

A

A class that is used for fetching data from the server, validating user input, or logging directly to the console – containing logic that we would like to separate from component-specific logic

Services can be injected into a class (and this helps maintain their singleton model) - thus they are marked with the @Injectable annotation

47
Q

What’s a module in angular?

A

A mechanism to group components, directives, pipes, and services that are related, in such a way that can be combined with other modules to create an application

Each angular application has to have the root module (@NgModule)

48
Q

How do you set up a new Angular app using the Angular CLI?

A

Npm install –g @angular/cli –> cd folder_path –> ng new project_name

49
Q

How do you generate a new Angular component using the Angular CLI?

A

Ng g c component_name

50
Q

What is a Single Page Application? What are the benefits/downsides of using an SPA?

A

A web design pattern where instead of navigation links going to separate pages, a link will change which components are displayed on a single page.

Components are loaded up-front so that navigation on a website is faster

Downside is that the first time the page loads it takes much longer

51
Q

What is routing? How do I create a new route?

A

A way to change what is displayed on an SPA that simulates page navigation

52
Q

What is a route guard?

A

Determines if a user can access a route, for example a user must log in to see their account details.

53
Q

What does it mean for components to be eagerly loaded?

A

The component is loaded into cache when the page is first accessed instead of when the component is to be displayed on the page.

54
Q

What are lifecycle hooks in Angular?

A

Lifecycle hooks are used to access components before their instance is deleted

55
Q

When does ngOnInit run?

A

After angular has initialized all data bound properties for additional initialization

56
Q

When does ngOnChange run?

A

When angular sets or resets data-bound input properties

57
Q

When does ngOnDestroy run?

A

Just before angular destroys a component or directive for cleanup to avoid memory leaks

58
Q

What is ngDoCheck?

A

A lifecycle hook that invokes a custom change-detection function for a directive, in addition to the check performed by the default change-detector.

59
Q

What is property binding, and its syntax?

A

The properties of HTML elements in the template can be dynamically modified by transferring data from TypeScript. It is used to set a specific element property.

i.e. <img [src] = ‘url_image> src is property bound to the variable ‘url_image’.

60
Q

What is event binding, and its syntax?

A

Event binding is the process that handles the event raised by the user to activate a template statement.
<button (click) = ‘submit()’

61
Q

What is 2 way data binding, and its syntax?

A

Conventionally two-way binding is achieved by combining binding/text interpolation and event binding. In Angular, this is achieved by [()].
<input [(ngModel)] = ‘input’>

62
Q

What is interpolation & its syntax?

A

Interpolation is used for one-way binding in Angular Framework. It embeds an expression into an HTML template.
{{ variable }}

63
Q

What are event emitters for?

A

create an instance of EventEmitter and annotate the property with the @Output decorator. This instance calls the emit() method to emit a payload which can be received by an event object $event.

64
Q

What do structural directives do in Angular?

A

Structural directives are used to modify the structure of the HTML DOM by adding, removing, or manipulating elements.
NgIf
NgFor
NgSwitch

65
Q

What does ngIf do?

A

NgIf is used to conditionally add or remove elements from the dom based on boolean expressions

66
Q

What does ngFor do?

A

NgFor is used to render a template for each item in a list or an array.

67
Q

What do attribute directives do in Angular?

A

Attribute directives are used to modify the behavior and appearance of existing HTML elements by applying custom attributes. These directives conditionally add, remove, or change values.

68
Q

What are pipes used for?

A

Pipes are used to transform data before displaying it in the template.

69
Q

Could you describe the pub/sub design?

A

Publisher/subscriber consist of a publisher (someone who sends a message) and a subscriber (someone to receive a message) and an intermediate component (event channel), where data is sent from a publisher to an event channel and the data is then filtered and sent to the subscriber. This means publishers and subscribers don’t need to know of each other.

70
Q

What are observables?

A

Observable is an invokable collection of future values or events. Observer is a collection of callbacks that listens to values delivered by the Observable and subscription is the execution of an Observable, aslo used for cancelling the execution.

71
Q

How do you use the HTTPClient?

A

The HttpClient module is already included when creating a new Angular app. To use it, we need to import the HttpClientModule in the app.module.ts. And include the HttpClient in the @NgModule’s import array. Then you can create a service file to handle all the HTTP requests.

72
Q

How do you pass data from a parent component to a child component in Angular?

A

Using the @Input() decorator allows the parent component to update data in the child component.

73
Q

How do you pass data from a child component to a parent component in Angular?

A

Using the @Output() decorator allows the child component to send data to the parent component. Bind an event to the child component that emits data using an EventEmitter.

74
Q

How would you maintain some variable globally across the Angular app?

A

Creating a service and then injecting it into the components that require that variable. Having getters and setters and importing the service where needed. You could also create a file to hold Constants and export, then import where needed.