Why JavaScript Developers Are Learning Rust
Every major JS tool is being rewritten in Rust: Turbopack, SWC, Biome, Oxlint, Rolldown, Lightning CSS, Tailwind v4βs Oxide engine. If youβre in the JS ecosystem, Rust is becoming unavoidable.
JavaScript β Rust Translation
Variables
// JavaScript
let name = "John"; // mutable
const age = 30; // immutable
// Rust
let mut name = "John"; // mutable
let age = 30; // immutable (default!)
Functions
// JavaScript
function add(a, b) { return a + b; }
// Rust
fn add(a: i32, b: i32) -> i32 { a + b }
Null Handling
// JavaScript β runtime crash if null
const user = getUser();
console.log(user.name); // π₯ if null
// Rust β compile-time safety
let user: Option<User> = get_user();
match user {
Some(u) => println!("{}", u.name),
None => println!("No user found"),
}
The Ownership System (The Hard Part)
This is where JS devs struggle. In JavaScript, the garbage collector handles memory. In Rust, YOU manage it through ownership rules:
- Each value has one owner
- When the owner goes out of scope, the value is dropped
- You can borrow references (read-only or mutable, not both)
let s1 = String::from("hello");
let s2 = s1; // s1 is MOVED to s2, s1 is invalid now!
// println!("{}", s1); // ERROR: s1 was moved
println!("{}", s2); // OK
Where to Start
- The Rust Book β free at doc.rust-lang.org/book
- Rustlings β interactive exercises
- Build a CLI tool β your first practical project
- Then try a web server with Axum or Actix