In a computer language, as long as there are three kinds of logic, sequential execution logic, branch logic and loop logic, the language can reach the Turing-complete state.
toy-js will be based on our own custom semantics in the
Language.md.You need to understand the lexical definition of computer language before you can understand the program. You can also use
Language.mdto help you get a better understanding based on MDN - lexical grammar grammar.
Tip: You should test by adhering to the content of the code block, otherwise unexpected errors will occur. These bugs are often features that are not currently implemented. Of course you can try to achieve it.
you can write the following code in the textarea and view the result after execution in the console.
// and &&
false && 1;
undefined && 1;
"" && 1;
0 && 1;
1 && 0;
// or ||
3 || 1;
undefined || 1;
// 略...var a; a = 1; a;o = { num: 1 }; o.num;// +
a = 6;
a = a + 2;
a;
// -
a = 6;
a = a - 2;
a;
// *
a = 6;
a = a * 2;
a;
// /
a = 6;
a = a / 2;
a;a = 1;
if(a) a = 2;
// or
if(a) {
a = 2;
}
a;a = 10;
while(a)
a = a - 1;
// or
while(a){
a = a - 1;
}
// or
while(a){
a = a - 1;
continue; // or break;
a = a - 100;
}
a;{
let a;
a = 1;
{
let b;
a = a + 1;
b = 10;
{
b = b / 2;
}
}
}
// 此时无法在外部访问 a 和 b
// or
{
let a;
a = 1;
{
let a;
a = 100;
}
a; // 1
}// log(); method is equivalent to console.log();
let x;
x = 1;
function a(){
log(x);
}
{
let x;
x = 2;
a();
}
// or
log(1, 2, 3);