Menu
CoddyTech
Course

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.

  1. 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…

    JavaScript
    1const ready = 2 < 5;2// The label is part of the output contract.3console.log(`ready=${ready}`);
    Rust
    1fn main() {2    let ready: bool = 2 < 5;3    // The label is part of the output contract.4    println!("ready={}", ready);5}
  2. 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…

    JavaScript
    1const label = "";2const count = 0;3console.log(label || "fallback");4console.log(!label && !count);
    Rust
    1fn main() {2    let label = "";3    let count = 0;4    println!("{}", label.is_empty());5    println!("{}", label.is_empty() && count == 0);6}
  3. 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…

    JavaScript
    1function invert(value) {2  return !value;3}4function forgot(value) {5  !value;6}7console.log(invert(false));8console.log(forgot(false));9console.log(invert(0));
    Rust
    1fn invert(value: bool) -> bool {2    !value3}4fn main() {5    println!("{}", invert(false));6}
  4. 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…

    JavaScript
    1function 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);
    Rust
    1fn 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}
  5. 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…

    JavaScript
    1const text = "A😀";2console.log(text.length, [...text].length);3for (const ch of text) {4  console.log(ch);5}
    Rust
    1fn main() {2    let text = "A😀";3    println!("{} {}", text.len(), text.chars().count());4    for ch in text.chars() {5        println!("{}", ch);6    }7}
  6. 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…

    JavaScript
    1const samples = [0, 8];2console.log(samples[5]);3console.log(samples[5] ?? 99);4console.log(samples[0] || 99);
    Rust
    1fn 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 questions

More courses for JavaScript developers

Learn Rust from another language

Frequently 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.

Coddy programming languages illustration

Start Rust for JavaScript Developers for free

Get started