Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSebastian Eguez
8,248 PointsWORDING
What is a variable? What is a constant? LIKE⦠I understand how they are different.
But these 2 = what? What do let and var have in common? Are they both a type? What is a type?
Does int = a type too?
1 Answer
Martel Storm
4,157 Points*** What is a type? Integers (numbers), Double (number with decimals), Float (Floating- point values), Bool (True or False), and String (Textual data). These words all associated with a Type of value.
There are also collection types such as: Array, Set, and Dictionaries. These are used for storing more than a single value to a constant or variable.
*** But these 2 = what? Variable = Variable Constant = Constant
*** Are they both a type? No, but they can be assigned types
*** What is a variable? *** What is a constant? *** What do let and var have in common?
Swift uses both Constants and Variables to store and refer to values (types). So you can store any one of those type values like Integers, Strings, or Arrays to a Constant or Variable.
let aNumber = 7
so in this case i've assigned the value of 7 to the constant "aNumber"
aNumber + aNumber = 14
The difference between let and var is that the value of "let" cannot be changed once assigned where as the value of "var" can be changed.
So like in the example below "aNumber" has the value of 7 and I cannot re assign it a different Integer value because it is a constant. If it was a variable I could re assign a new Integer value to it .
(example of a variable being changed) var aNumber = 7 aNumber = 8
Now aNumber = 8
(an example of how a constant CANNOT be changed) let aNumber = 7 aNumber = 8
This would give you an error aNumber still equals 7
Man I hope that helps happy coding friend!
Sebastian Eguez
8,248 PointsSebastian Eguez
8,248 PointsU rock!