Message output
JavaScript | Swift |
---|---|
console.log("Hello world!") |
print("Hello world!") |
Variables
JavaScript | Swift |
---|---|
const pi = 3.14 |
let pi = 3.14 |
let name = "Michael" |
var name = "Michael" |
String interpolation
JavaScript | Swift |
---|---|
`Michael is ${age} years old` |
"Michael is \(age) years old" |
Javascript
let intro = `
This is a story about a boy.
His name was ${name}
`
Swift
var intro = """
This is a story about a girl.
Her name was \(name)
"""
Array
JavaScript | Swift |
let names = ["John", "Jill", "Mary"] |
var names = ["John", "Jill", "Mary"] |
Object/Dictionary
JavaScript
let car = {
"make": "Audi",
"model": "A3",
"color": "White"
}
Swift
var car = [
"make": "Audi",
"model": "A3",
"color": "White"
]