Skip to content

conditionals

HebiKotei edited this page Feb 26, 2023 · 2 revisions

Conditionals

Default Values

Smart use of the 'or' operator instead of nil checks increases readability.

    if name then
        return name
    else
        return "John Doe"
    end
    return name or "John Doe"

Don't write "if true then return true"

Just use ternary operators to evaluate the expression

    if name == "mark" or name == "stacy"
        return true
    else
        return false
    end
    return name == "mark" or name == "stacy" -- Will return true if name is either mark or stacy
Clone this wiki locally