Menu
CoddyTech
Course

Lua for JavaScript Developers

Transfer JavaScript experience to Lua 5.1: truth rules, tables, functions, module exports, errors and metatable objects. Build a stock ledger and port two source-language reference programs.

JavaScript and Lua side by side

The same program in JavaScript and in Lua, from the lessons of this course.

  1. Print and Comment

    JavaScript concatenates strings with +; Lua uses .. and print separates multiple arguments with tabs. Build one string for exact spacing.

    JavaScript
    1console.log("Hi" + ", Ada");
    Lua
    1print("Hi" .. ", Ada")
  2. Undefined and Missing Fields

    An object can retain a JavaScript property whose value is undefined. A Lua table field assigned nil is removed. False remains a stored Lua value.

    JavaScript
    1const record = {x: undefined};2console.log("x" in record);
    Lua
    1local d = {x = nil}2print(d.x == nil)
  3. Ranges to Numeric for

    JavaScript for has an explicit condition and update. Lua numeric for includes its limit, so the corresponding range is for i=1,3 do. A negative step is needed for descending Lua loops.

    JavaScript
    1let total = 0;2for (let i = 1; i < 4; i++) total += i;3console.log(total);
    Lua
    1local total = 02for i = 1, 3 do total = total + i end3print(total)
  4. Functions and Returns

    JavaScript and Lua functions are values. Missing JavaScript arguments become undefined; missing Lua arguments become nil. Lua uses function/end and no arrow syntax.

    JavaScript
    1function twice(x) { return x * 2; }2console.log(twice(4));
    Lua
    1local function twice(x) return x * 2 end2print(twice(4))
  5. Lists as Dense Tables

    JavaScript splice removes and shifts elements. Lua table.remove does the same with one-based indexes. JavaScript delete and Lua assignment to nil both risk holes instead of a dense sequence.

    JavaScript
    1const a=["a","b","c"];2a.splice(1,1);3console.log(a.join(","));
    Lua
    1local a = {"a", "b", "c"}2table.remove(a, 2)3print(table.concat(a, ","))
  6. Sorting and Comparators

    JavaScript sort mutates and returns the array; its comparator returns a signed number. Lua table.sort mutates but returns no result, and its comparator returns a strict boolean ordering.

    JavaScript
    1const a=[3,1,2];2a.sort((x,y)=>x-y);3console.log(a[0]);
    Lua
    1local a={3,1,2}2table.sort(a)3print(a[1])

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

More courses for JavaScript developers

Learn Lua from another language

Frequently asked questions

Who is Lua for JavaScript Developers for?

For people who already write JavaScript and want to learn Lua. Each lesson starts from JavaScript you know and shows how Lua does the same thing, so you skip the beginner basics.

Do I need to know Lua already?

No. The course starts with your first Lua program. You need JavaScript basics: variables, conditions, loops, functions and collections.

How many lessons does Lua for JavaScript Developers have?

Lua for JavaScript Developers contains 48 interactive lessons you can complete at your own pace.

What does Lua for JavaScript Developers cover?

The course is organized into chapters covering: First Lua Programs, Values and Decisions, Iteration and Flow, Functions and Closures, and more.

Is Lua 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 Lua for JavaScript Developers for free

Get started