Browse Source

Create null.md

Marco Bambini 6 years ago
parent
commit
d1fcf802f4
1 changed files with 25 additions and 0 deletions
  1. 25 0
      docs/null.md

+ 25 - 0
docs/null.md

@@ -0,0 +1,25 @@
+### Null
+
+It indicates the absence of a value. If you call a method that doesn’t return anything and get its returned value, you get null back. The null data type is also used to initialize uninitialized variables with a default value.
+```swift
+	class Newton {
+		var mass = 10;
+		var acceleration;
+		func force() {
+			return mass * acceleration;
+		}
+	}
+
+	func f2() {
+		var sir = Newton();
+		// acceleration instance variable has no default value
+		// so it is automatically set to null
+		return sir.force();
+	}
+
+	func f1() {
+		var a;
+		// a is uninitialized so it has a default null value
+		return a;
+	}
+```