Issue and pull request are welcome, please!
Swift
// declare a constant
let maximumNumberOfLoginAttempts = 10
// declare a variable
var currentLoginAttempt = 0
// declare multiple constants or multiple variables on a single line, separated by commas
var x = 0.0, y = 0.0, z = 0.0
JavaScript
// declare a constant
const maximumNumberOfLoginAttempts = 10
// declare a variable
var currentLoginAttempt = 0
// or
let currentLoginAttempt = 0
// declare multiple constants or multiple variables on a single line, separated by commas
var x = 0.0, y = 0.0, z = 0.0
Swift
// This is a comment.
/* This is also a comment
but is written over multiple lines. */
JavaScript
// This is a comment.
/* This is also a comment
but is written over multiple lines. */
Swift
let pi = 3.14159
// Integer and Floating-Point Conversion
let integerPi = Int(pi)
JavaScript
const pi = 3.14159
// Integer and Floating-Point Conversion
const integerPi = parseInt(pi)
Swift
let orangesAreOrange = true
let turnipsAreDelicious = false
if turnipsAreDelicious {
print("Mmm, tasty turnips!")
} else {
print("Eww, turnips are horrible.")
}
JavaScript
const orangesAreOrange = true
const turnipsAreDelicious = false
if (turnipsAreDelicious) {
console.log("Mmm, tasty turnips!")
} else {
console.log("Eww, turnips are horrible.")
}
Swift
func canThrowAnError() throws {
// this function may or may not throw an error
}
do {
try canThrowAnError()
// no error was thrown
} catch {
// an error was thrown
}
JavaScript
function canThrowAnError() {
// this function may or may not throw an error
}
try {
canThrowAnError()
// no error was thrown
} catch (e) {
// an error was thrown
}