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: Data-Types.md
+24-1Lines changed: 24 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,29 @@
1
1
# Data Types
2
2
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
0 commit comments