Lua Interview Questions: What are the differences between Lua and JavaScript?

Lua programming language Interview Question with Answer FAQ:

What are the differences between Lua and JavaScript?
Following are the difference between both scripting language (Lua and JavaScript)

  • Lua has native support for coroutines.
  • Lua doesn't convert between types for any comparison operators. In JS, only === and !== don't type juggle.
  • Lua has an exponentiation operator (^); JS doesn't. JS has many more operators, including the ternary conditional operator (?:), increment/decrement, bitwise operators, type operators (typeof and instanceof), additional assignment operators and additional comparison operators.
  • In JS, the equals and not equals operators are of lower precedence than less than et al. In Lua, all comparison operators are the same precedence.
  • Lua supports tail calls.
  • Lua supports assignment to a list of variables. While it isn't yet standard in Javascript, Mozilla's JS engine (and Opera's, to an extent) has supported a similar feature since JS 1.7 (available as part of Firefox 2) under the name "destructuring assignment". Destructuring in JS is more general, as it can be used in contexts other than assignment, such as function definitions & calls and loop initializers. Destructuring assignment has been a proposed addition to ECMAScript (the language standard behind Javascript) for awhile.
  • In Lua, you can overload operators.
  • In Lua, you can manipulate environments with getfenv & setfenv.
  • In JS, all functions are variadic. In Lua, functions must be explicitly declared as variadic.
  • Foreach in JS loops over object properties. Foreach in Lua (which use the keyword for) loops over iterators and is more general.
  • Integer literals in JS can be in octal.
  • JS has explicit Unicode support.
  • In Lua, ~ is used in place of !. (as in, if foo ~= 20 then ... end) (technically syntax, but it's easily overlooked and causes subtle bugs).
  • In Lua, the not/or/and keywords are used in place of !/||/&& (also syntax but also easily forgotten).
  • In Lua, any type of value (except nil and NaN) can be used to index a table; in JavaScript, object indexes are converted to strings.
  • Not equal is spelled ~= in Lua. In JS it is !=
  • Lua arrays are 1-based - their first index is 1 rather than 0.
  • Lua requires a colon rather than a period to call object methods. You write a:foo() instead of 
For more Lua Interview Question Click here



Contact Form