Swift for JavaScript Developers
Move from JavaScript to Swift through static types, optionals, value semantics, Unicode, protocols and ARC. Complete 48 multi-file exercises, build a parcel desk in four stages and port two complete JavaScript programs.
JavaScript and Swift side by side
The same program in JavaScript and in Swift, from the lessons of this course.
Bindings and Mutation
JavaScript const prevents rebinding a local but does not freeze the object it references. Both names here refer to one mutable array, so changing its length is visible through either name. Object.freeze adds a separate shallow runtime restriction and still…
JavaScript1const pending = ["upload", "index"];2const alias = pending;3alias.length = 0;4console.log(pending.length, alias.length);Swift1import Foundation2let pending = ["upload", "index"]3var copy = pending4copy.removeAll()5print(pending.count, copy.count)Strings and Interpolation
JavaScript template literals interpolate expressions inside ${...} and create string values. Swift String interpolation uses a backslash followed by parentheses instead. Both examples construct a path, test its prefix and create a repeated marker, but the…
JavaScript1const folder = "cache";2const path = `${folder}/image`;3console.log(path.startsWith("cache/"));4console.log(".".repeat(3));Swift1import Foundation2let folder = "cache"3let path = "\(folder)/image"4print(path.hasPrefix("cache/"))5print(String(repeating: ".", count: 3))Switch and Patterns
JavaScript can classify related values with ordered comparisons; its switch uses case-value matching and can fall through without an exit. Swift switch supports richer patterns, including tuple components and wildcards, and does not implicitly fall through.…
JavaScript1function axis(x, y) {2 if (x === 0 && y === 0) return "origin";3 if (x === 0) return "vertical";4 return "other";5}6console.log(axis(0, 9));Swift1import Foundation2func axis(_ x: Int, _ y: Int) -> String {3 switch (x, y) {4 case (0, 0): return "origin"5 case (0, _): return "vertical"6 default: return "other"7 }8}Functions and Labels
JavaScript functions receive positional arguments, and an options object can supply named data by convention. That object is still one argument, not a language-level external argument label. Swift distinguishes the label at the call site from the parameter…
JavaScript1function mark(text, options) { return options.prefix + text; }2console.log(mark("draft", {prefix: "!"}));Swift1import Foundation2func mark(_ text: String, with prefix: String) -> String { prefix + text }Dictionaries and Missing Keys
JavaScript Map.get returns undefined for a missing key, which can be ambiguous if undefined itself is stored; has checks membership separately. Map.delete removes an entry, while set(key, undefined) would retain it. Assigning a Map to another variable shares…
JavaScript1const flags = new Map([["cache", true]]);2flags.delete("cache");3console.log(flags.get("cache") ?? false);4console.log(flags.size);Swift1import Foundation2var flags = ["cache": true]3flags["cache"] = nil4print(flags["cache"] ?? false)5print(flags.count)Structs and Independent Copies
A JavaScript object literal creates a reference object. Assigning it to second preserves the same identity, so changing enabled is visible through first. A new object created with spread could copy its outer properties, but nested objects would still be…
JavaScript1const first = {enabled: false};2const second = first;3second.enabled = !second.enabled;4console.log(first.enabled, second.enabled);Swift1import Foundation2struct Toggle {3 var enabled: Bool4 mutating func flip() { enabled.toggle() }5}
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsStarting Swift
5 lessonsText and Decisions
5 lessonsControl Flow
5 lessonsFunctions and Arrays
5 lessonsCollection Tools
5 lessonsValues and References
5 lessonsFailures and Abstraction
6 lessonsDesigning Types
6 lessonsParcel Desk Project
4 lessonsJavaScript Ports
2 lessonsFrequently asked questions
Who is Swift for JavaScript Developers for?
For people who already write JavaScript and want to learn Swift. Each lesson starts from JavaScript you know and shows how Swift does the same thing, so you skip the beginner basics.
Do I need to know Swift already?
No. The course starts with your first Swift program. You need JavaScript basics: variables, conditions, loops, functions and collections.
How many lessons does Swift for JavaScript Developers have?
Swift for JavaScript Developers contains 48 interactive lessons you can complete at your own pace.
What does Swift for JavaScript Developers cover?
The course is organized into chapters covering: Starting Swift, Text and Decisions, Control Flow, Functions and Arrays, and more.
Is Swift for JavaScript Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.