Original articles, welcome reprint. Reprint Please specify: Dongsheng's Blog
Use Var or let?
In the course of our development, when is the definition of the keyword Var, or is it defined as let?
Actually AH all can satisfy our demand, then how should we choose?
For example, you can define PI π as let or var.
letπ= 3.14159
varπ= 3.14159
The above code compiles without error. However, from the business logic level, π should be defined as a constant (let), since constants (let) cannot be modified on the one hand, and the use of constants (let) in the program can improve the readability of the program.
I think: In principle, let is preferred, it has many advantages, it can prevent unnecessary changes in the process of running the program, improve the readability of the program. In particular, a let declaration is often used when referencing a data type declaration, although it is not a constant at the business level, but rather prevents the program from being incorrectly modified by its reference while it is running.
Welcome to follow Dongsheng Sina Weibo @tony_ Dongsheng.
Learn about the latest technical articles, books, tutorials and information on the public platform of the smart Jie classroom
More Products iOS, Cocos, mobile design courses please pay attention to the official website of Chi Jie Classroom: http://www.zhijieketang.com
Luxgen Classroom Forum Website: http://51work6.com/forum.php
Swift 2.0 Learning Notes (Day 6)--what time do constants and variables use?