Rust for JavaScript Developers
Move from JavaScript objects, arrays, and runtime checks to Rust ownership, borrowing, enums, and traits. Complete 48 multi-file lessons, build a parcel depot, and port two JavaScript programs.
JavaScript and Rust side by side
The same program in JavaScript and in Rust, from the lessons of this course.
Output and Comments
JavaScript runs a script from top to bottom, and console.log accepts any values and converts them to text at runtime. Rust compiles native code, starts at fn main(), and checks formatting arguments before the program runs. Both languages use // line comments…
JavaScript1const ready = 2 < 5;2// The label is part of the output contract.3console.log(`ready=${ready}`);Rust1fn main() {2 let ready: bool = 2 < 5;3 // The label is part of the output contract.4 println!("ready={}", ready);5}Boolean Conditions
JavaScript conditions run on truthiness: 0, "", NaN, null and undefined all select the false branch, and everything else selects the true one. Its logical operators also return one of their operands, so label || "fallback" yields a string rather than a…
JavaScript1const label = "";2const count = 0;3console.log(label || "fallback");4console.log(!label && !count);Rust1fn main() {2 let label = "";3 let count = 0;4 println!("{}", label.is_empty());5 println!("{}", label.is_empty() && count == 0);6}Functions and Returns
A JavaScript function declares no parameter or return types. Any value can be passed, missing arguments become undefined, and a function that reaches its closing brace without return gives the caller undefined. A forgotten return therefore fails quietly, as…
JavaScript1function invert(value) {2 return !value;3}4function forgot(value) {5 !value;6}7console.log(invert(false));8console.log(forgot(false));9console.log(invert(0));Rust1fn invert(value: bool) -> bool {2 !value3}4fn main() {5 println!("{}", invert(false));6}Ownership and Moves
JavaScript objects are shared by reference. Assigning an object to another variable, or passing it to a function, copies the reference, so every name reaches the same object and a change made through one is visible through all of them. The garbage collector…
JavaScript1function stamp(record) {2 record.text += ":sent";3 return record;4}5const original = { text: "ready" };6const owner = stamp(original);7console.log(original.text);8console.log(owner === original);Rust1fn stamp(mut text: String) -> String {2 text.push_str(":sent");3 text4}5fn main() {6 let original = String::from("ready");7 let owner = stamp(original);8 println!("{}", owner);9}Strings and UTF-8
JavaScript strings are sequences of UTF-16 code units. .length counts those units, and text[i] returns one of them, so an emoji outside the Basic Multilingual Plane counts as two and can be split into half of a surrogate pair. The for...of loop and the spread…
JavaScript1const text = "A😀";2console.log(text.length, [...text].length);3for (const ch of text) {4 console.log(ch);5}Rust1fn main() {2 let text = "A😀";3 println!("{} {}", text.len(), text.chars().count());4 for ch in text.chars() {5 println!("{}", ch);6 }7}Option and Matching
In JavaScript, reading a missing array element or object property does not fail: it quietly produces undefined, and other code may use null for the same idea. Nothing forces a caller to check before using the value. Rust Option<T> makes presence a declared…
JavaScript1const samples = [0, 8];2console.log(samples[5]);3console.log(samples[5] ?? 99);4console.log(samples[0] || 99);Rust1fn main() {2 let samples = [0, 8];3 println!("{:?}", samples.get(5));4 println!("{}", match samples.get(5) { Some(n) => *n, None => 99 });5 println!("{}", match samples.get(0) { Some(n) => *n, None => 99 });6}
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsFirst Rust Programs
6 lessonsDecisions and Loops
5 lessonsFunctions and Sequences
4 lessonsOwnership and Borrowing
5 lessonsText and Collections
4 lessonsAbsence and Failure
5 lessonsStructs and State
6 lessonsTraits and Generic Code
7 lessonsProject: Parcel Depot
4 lessonsFinal Ports
2 lessonsFrequently asked questions
Who is Rust for JavaScript Developers for?
For people who already write JavaScript and want to learn Rust. Each lesson starts from JavaScript you know and shows how Rust does the same thing, so you skip the beginner basics.
Do I need to know Rust already?
No. The course starts with your first Rust program. You need JavaScript basics: variables, conditions, loops, functions and collections.
How many lessons does Rust for JavaScript Developers have?
Rust for JavaScript Developers contains 48 interactive lessons you can complete at your own pace.
What does Rust for JavaScript Developers cover?
The course is organized into chapters covering: First Rust Programs, Decisions and Loops, Functions and Sequences, Ownership and Borrowing, and more.
Is Rust 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.