YogeshChauhan . com

What is the difference between let and var in Swift?

in Swift on February 28, 2020

let = Constant and var = variables. Period. As simple as that. Values of constants can not be changed but values of variables can be changed.

Constants and Variables

Constants and variables associate a name with a value of a particular type (such as the number 10 or the string "Hello"). The value of a constant can’t be changed once it’s set, whereas a variable can be set to a different value in the future.

Declaring Constants and Variables

Constants and variables must be declared before they’re used. You declare constants with the let keyword and variables with the var keyword. Here’s an example of how constants and variables can be used to track the number of login attempts a user has made:


let maximumNumberOfLoginAttempts = 10
var currentLoginAttempt = 0

In the example above, value of maximumNumberOfLoginAttempts can not be changed but value of currentLoginAttempt can and will be changed as user tries to log in each time.

amazon

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

Jun 16 What are Stored Procedures for SQL Server? Jun 16 What are Class Constants in PHP? Jun 15 A short basic guide on states in React Jun 15 How to define constants in PHP? Jun 15 How to define visibility for a property in PHP? Jun 15 How to use @if and @else in SCSS?

You might also like these

Introduction to components and templates Part 3: Data bindingAngularHow to load a module with configuration in SCSS?SCSSHow to draw an SVG path on scroll using JavaScript?JavaScriptSpecificity of attribute selectorsCSSHow to Write Complex Search Queries in SQL?SQL/MySQLHow to remove trailing characters from a string using JavaScript?JavaScriptHow to obfuscate JavaScript code to hide it from View Source?JavaScriptWhat Is a Graph Database?MiscHow to check if the page is single post page in WordPress?WordPressCheck If a String Contains a Specific Word in PHPPHPLearn to create your skill bar using CSSCSSHow to define variables in SCSS (Sass)?SCSS