What is the difference between lua and javascript
Difference: 1. The comment code of JavaScript is "//", and the comment code of Lua is "--"; 2. JavaScript uses val to declare global variables and there are no local variables, while Lua does not need to be directly positioned. are global variables, and local declarations are local variables.
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
What is the difference between lua and javascript
Comparison of the differences between Lua and Javascript
Lua simulator js solution
1. Syntax level simulation
Differences between lua and js language
1.1 Comments
js is //, lua is --.
1.2 Variables
js uses val to declare global variables and there are no local variables, while lua does not need to be positioned directly. are global variables, and local declarations are local variables.
1.3 Operator
js
- * / % --
= = -= *= /= %=
Supported strings
txt1 = "what a very";
txt2 = "nice day";
txt3 =txt1 " " txt2;
The output result of printing txt3 is "what a very nice day".
Rule:
Compare numbers with strings Add, the result will become a string.
lua
binary: - * / ^ %
uniary:- (Minus sign)
lua strings are spliced into ..
For example, "Hello ".."World" is spliced into Hello World
1.4 Relational Operator
js relational operator
== === (congruent) != > < >= < =
lua relational operator
1.5 Logical operators
- ##js
- && || !
- lua
- and or not
- js class c
- if else
- lua
- if then else
if then
elseif then
else
end
There must be end
1.7 Switch statementlua does not support Switch statement
1.8 Message box
- js
- Alert box alert("text")
Confirm box prompt("text","default value")
- lua
- Extended support for warning boxes and confirmation boxes
##js
-
js with {} class c
function 函数名(参数) { 代码... }
Copy after login
- lua class vb script
function 函数名( 参数) end
Copy after login
2.0 For loop
js: Class c
for (i=0;i<=10;i++) { document.write("The number is " + i) document.write("<br />") }
for var= exp1,exp2,exp3 do <执行体> end
for i =1,100 do print(i) end for i =1,100,2 do print(i) end
--打印数组a 的所有值 for i,v in pairs(a) do print(v) end
---打印table t中所以的key for k in pairs(t) do print(k) end
2.1 While loop
js: Class c
while (变量<=结束值) { 需执行的代码 } lua: i =1; while a[i] do print(a[i]) i = i+1; end
repeat: line = io.read() until line~="" print(line)
2.2 Break and Continue
js: There are two types of c
- that can be used in loops Statements in: break and continue
<script type="text/javascript"> var i=0 for (i=0;i<=10;i++) { if (i==3){break} document.write("The number is " + i) document.write("<br />") } </script> Continue
<script type="text/javascript"> var i=0 for (i=0;i<=10;i++) { if (i==3){continue} document.write("The number is " + i) document.write("<br />") } </script>
- supports break, but does not support continue.
local i =1 while a[i] do if a[i] == v then break end i = i +1 end
2.3 For... In statement
js: Use the For...In statement to specifically traverse the elements in the array.
For...In statement is used to loop through the properties of an array or object. for ... in Each time the code in the loop is executed, an operation will be performed on the elements of the array or the properties of the object. Syntax:for (变量 in 对象) { 在此执行代码 }
<script type="text/javascript"> var x var mycars = new Array() mycars[0] = "Saab" mycars[1] = "Volvo" mycars[2] = "BMW" for (x in mycars) { document.write(mycars[x] + "<br />") } </script>
javascript learning tutorial
The above is the detailed content of What is the difference between lua and javascript. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.
