Skip to content

Commit 1849f22

Browse files
authored
Update Data-Types.md
1 parent 68ef45c commit 1849f22

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

Data-Types.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
# Data Types
22

3-
JavaScript is a weakly typed language.
3+
JavaScript is a weakly (loosely) typed language as opposed to Swift that is a strongly typed language.
4+
5+
#### Example of a weakly typed language
6+
7+
In this example the type `name` is not strongly tied to forever be a `String`. Re-assigning the data type to be a `Number` does not cause a compile-time error like a language like Swift. This causes the developer to check types when working through various coding logic.
8+
9+
```javascript
10+
let name = "Alex";
11+
name = 10;
12+
13+
console.log(`${name + 7}`); // name here is a number
14+
```
15+
16+
#### Example of a strongly typed language
17+
18+
In this Swift example we would get a compile time error as we cannot re-assign the name data type to an `Int`.
19+
20+
```swift
21+
var name = "Alex";
22+
name = 10; // COMPILER ERROR - cannot assign type Int to expected type String
23+
24+
print("\(name + 7)") // name here is a number
25+
```
26+
427

528
## Simple Types
629

0 commit comments

Comments
 (0)