Luau for JavaScript Developers
Transfer JavaScript skills to general Luau: truth rules, typed signatures, runtime validation, table collections, relative modules and metatable objects. Build a stock ledger and port two source programs.
JavaScript and Luau side by side
The same program in JavaScript and in Luau, from the lessons of this course.
Print and Comment
JavaScript uses + and template literals; Luau uses .. and backtick interpolation with braces instead of dollar-braces. console.log is a host API, while print is the Luau output function.
JavaScript1console.log("Hi" + ", Ada");Luau1local name = "Ada"2print(`Hi, {name}`)Missing Fields and Optionals
An own JavaScript property can exist with value undefined. Assigning nil removes a Luau table key. Port property-presence checks deliberately instead of translating undefined to a stored nil field.
JavaScript1const record = {x: undefined};2console.log("x" in record);Luau1local d = {x = nil}2print(d.x == nil)Inclusive Numeric Loops
JavaScript for spells out initialization, condition and update. Luau numeric for includes its upper bound. Translate an exclusive JavaScript stop value to an inclusive Luau endpoint.
JavaScript1let total = 0;2for (let i = 1; i < 4; i++) total += i;3console.log(total);Luau1local total = 02for i = 1, 3 do total = total + i end3print(total)Functions and Returns
JavaScript functions accept omitted arguments as undefined; Luau receives nil. Both can pass functions as values. Luau additionally accepts erased signature annotations, but Run will not statically reject a wrong argument type.
JavaScript1function twice(x) { return x * 2; }2console.log(twice(4));Luau1local function twice(x: number): number return x * 2 end2print(twice(4))Lists as Dense Tables
JavaScript arrays combine indexed storage, methods and a length property. Luau uses ordinary tables plus library operations. Keep sequence keys dense and do not copy zero-based array offsets.
JavaScript1const a=["a","b","c"];2a.splice(1,1);3console.log(a.join(","));Luau1local a = {"a", "b", "c"}2table.remove(a, 2)3print(table.concat(a, ","))Sorting and Comparators
JavaScript Array.sort comparators return a negative, zero or positive number. Luau table.sort comparators return booleans. Returning a numeric difference in Luau makes even zero truthy and breaks the ordering contract.
JavaScript1const a=[3,1,2];2a.sort((x,y)=>x-y);3console.log(a[0]);Luau1local a={3,1,2}2table.sort(a)3print(a[1])
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsFirst Luau Programs
6 lessonsValues and Decisions
5 lessonsIteration and Flow
5 lessonsFunctions and Closures
5 lessonsTables as Collections
5 lessonsOrdering, Modules and Errors
5 lessonsObjects and Owned State
5 lessonsComposition and Object Lookup
6 lessonsProject: Stock Ledger
4 lessonsFinal Source Ports
2 lessonsFrequently asked questions
Who is Luau for JavaScript Developers for?
For people who already write JavaScript and want to learn Luau. Each lesson starts from JavaScript you know and shows how Luau does the same thing, so you skip the beginner basics.
Do I need to know Luau already?
No. The course starts with your first Luau program. You need JavaScript basics: variables, conditions, loops, functions and collections.
How many lessons does Luau for JavaScript Developers have?
Luau for JavaScript Developers contains 48 interactive lessons you can complete at your own pace.
What does Luau for JavaScript Developers cover?
The course is organized into chapters covering: First Luau Programs, Values and Decisions, Iteration and Flow, Functions and Closures, and more.
Is Luau 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.