You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: chapters/1-basics/1-type-annotations/README.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,14 +4,14 @@ In TypeScript, you can specify the type of a variable, function, or class by add
4
4
5
5
This helps you catch bugs in your code before you run it, and makes your code more readable and maintainable.
6
6
7
-
To appreciate the benefits of having types, let's first look at a problem with Javascript.
7
+
To appreciate the benefits of having types, let's first look at a problem with JavaScript.
8
8
9
-
## The problem with Javascript
9
+
## The problem with JavaScript
10
10
11
-
Here, we have a Javascript function `add`, which takes in `a` and `b` as parameters, and returns the sum of `a` and `b`. Pretty straightforward.
11
+
Here, we have a JavaScript function `add`, which takes in `a` and `b` as parameters, and returns the sum of `a` and `b`. Pretty straightforward.
12
12
13
13
```ts
14
-
// add.js (Javascript)
14
+
// add.js (JavaScript)
15
15
function add(a, b) {
16
16
returna+b;
17
17
}
@@ -23,7 +23,7 @@ We know that `a` and `b` should be numbers because we are adding them together.
23
23
In fact, we can pass in any value to `add` and it will still run.
24
24
25
25
```js
26
-
// add.js (Javascript)
26
+
// add.js (JavaScript)
27
27
functionadd(a, b) {
28
28
return a + b;
29
29
}
@@ -68,12 +68,12 @@ function add(a: number, b: number): number {
68
68
}
69
69
```
70
70
71
-
In Typescript, type annotations are done by adding the type after the variable name, separated by a colon `:`. In this case, we are specifying that `a` and `b` are of type `number`.
71
+
In TypeScript, type annotations are done by adding the type after the variable name, separated by a colon `:`. In this case, we are specifying that `a` and `b` are of type `number`.
0 commit comments