Tutorial by Examples: al

Operands of the abstract equality operator are compared after being converted to a common type. How this conversion happens is based on the specification of the operator: Specification for the == operator: 7.2.13 Abstract Equality Comparison The comparison x == y, where x and y are values, prod...
When both operands are numeric, they are compared normally: 1 < 2 // true 2 <= 2 // true 3 >= 5 // false true < false // false (implicitly converted to numbers, 1 > 0) When both operands are strings, they are compared lexicographically (according to alphabeti...
Operator != is the inverse of the == operator. Will return true if the operands aren't equal. The javascript engine will try and convert both operands to matching types if they aren't of the same type. Note: if the two operands have different internal references in memory, then false will be ret...
The filter() method creates an array filled with all array elements that pass a test provided as a function. 5.1 [1, 2, 3, 4, 5].filter(function(value, index, arr) { return value > 2; }); 6 [1, 2, 3, 4, 5].filter(value => value > 2); Results in a new array: [3, 4, 5] Fi...
Consider a database with the following two tables. Employees table: IdFNameLNameDeptId1JamesSmith32JohnJohnson4 Departments table: IdName1Sales2Marketing3Finance4IT Simple select statement * is the wildcard character used to select all available columns in a table. When used as a substitute f...
The JSONSerialization class is built into Apple's Foundation framework. 2.2 Read JSON The JSONObjectWithData function takes NSData, and returns AnyObject. You can use as? to convert the result to your expected type. do { guard let jsonData = "[\"Hello\", \"JSON\"]&q...
Enum cases can contain one or more payloads (associated values): enum Action { case jump case kick case move(distance: Float) // The "move" case has an associated distance } The payload must be provided when instantiating the enum value: performAction(.jump) performA...
Enums without payloads can have raw values of any literal type: enum Rotation: Int { case up = 0 case left = 90 case upsideDown = 180 case right = 270 } Enums without any specific type do not expose the rawValue property enum Rotation { case up case right cas...
Logical OR (||), reading left to right, will evaluate to the first truthy value. If no truthy value is found, the last value is returned. var a = 'hello' || ''; // a = 'hello' var b = '' || []; // b = [] var c = '' || undefined; // c = undefined var d = 1 |...
Breaking out of a while loop var i = 0; while(true) { i++; if(i === 42) { break; } } console.log(i); Expected output: 42 Breaking out of a for loop var i; for(i = 0; i < 100; i++) { if(i === 42) { break; } } console.log(i); Expected o...
Continuing a "for" Loop When you put the continue keyword in a for loop, execution jumps to the update expression (i++ in the example): for (var i = 0; i < 3; i++) { if (i === 1) { continue; } console.log(i); } Expected output: 0 2 Continuing a While...
Using the def statement is the most common way to define a function in python. This statement is a so called single clause compound statement with the following syntax: def function_name(parameters): statement(s) function_name is known as the identifier of the function. Since a function def...
Functions can return a value that you can use directly: def give_me_five(): return 5 print(give_me_five()) # Print the returned value # Out: 5 or save the value for later use: num = give_me_five() print(num) # Print the saved returned value # Out: 5 or use the value f...
The setTimeout() method calls a function or evaluates an expression after a specified number of milliseconds. It is also a trivial way to achieve an asynchronous operation. In this example calling the wait function resolves the promise after the time specified as first argument: function wait(ms) ...
git add -A 2.0 git add . In version 2.x, git add . will stage all changes to files in the current directory and all its subdirectories. However, in 1.x it will only stage new and modified files, not deleted files. Use git add -A, or its equivalent command git add --all, to stage all ch...
Optionals are a generic enum type that acts as a wrapper. This wrapper allows a variable to have one of two states: the value of the user-defined type or nil, which represents the absence of a value. This ability is particularly important in Swift because one of the stated design objectives of the ...
x != y This returns True if x and y are not equal and otherwise returns False. 12 != 1 # True 12 != '12' # True '12' != '12' # False
x == y This expression evaluates if x and y are the same value and returns the result as a boolean value. Generally both type and value need to match, so the int 12 is not the same as the string '12'. 12 == 12 # True 12 == 1 # False '12' == '12' # True 'spam' == 'spam' # True 'spam' == ...
from module_name import * for example: from math import * sqrt(2) # instead of math.sqrt(2) ceil(2.7) # instead of math.ceil(2.7) This will import all names defined in the math module into the global namespace, other than names that begin with an underscore (which indicates that the wri...

Page 6 of 269